<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>日志⭐⭐ | VitePress</title>
    <meta name="description" content="A VitePress site">
    <link rel="preload stylesheet" href="/notebook/assets/style.3dbfd0c2.css" as="style">
    
    <script type="module" src="/notebook/assets/app.8aaa4cbe.js"></script>
    <link rel="preload" href="/notebook/assets/inter-roman-latin.2ed14f66.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/notebook/assets/chunks/framework.1336c4e5.js">
    <link rel="modulepreload" href="/notebook/assets/chunks/theme.20cddc0c.js">
    <link rel="modulepreload" href="/notebook/assets/2、数据库_MySQL_MySQL核心_运维.md.83f97c16.lean.js">
    <script id="check-dark-light">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-255ec12d><!--[--><!--]--><!--[--><span tabindex="-1" data-v-ae3e3f51></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-ae3e3f51> Skip to content </a><!--]--><!----><header class="VPNav" data-v-255ec12d data-v-7e5bc4a5><div class="VPNavBar has-sidebar" data-v-7e5bc4a5 data-v-0937f67c><div class="container" data-v-0937f67c><div class="title" data-v-0937f67c><div class="VPNavBarTitle has-sidebar" data-v-0937f67c data-v-86d1bed8><a class="title" href="/notebook/" data-v-86d1bed8><!--[--><!--]--><!--[--><img class="VPImage logo" src="/notebook/Vue.png" alt data-v-8426fc1a><!--]--><!--[-->任硕的文档<!--]--><!--[--><!--]--></a></div></div><div class="content" data-v-0937f67c><div class="curtain" data-v-0937f67c></div><div class="content-body" data-v-0937f67c><!--[--><!--]--><div class="VPNavBarSearch search" style="--vp-meta-key:&#39;Meta&#39;;" data-v-0937f67c><!--[--><!----><div id="docsearch"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg class="DocSearch-Search-Icon" width="20" height="20" viewBox="0 0 20 20" aria-label="search icon"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-0937f67c data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>Main Navigation</span><!--[--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>Java学前端</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/HTML+JS.html" data-v-2f2cfafc><!--[-->HTML+JS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/CSS.html" data-v-2f2cfafc><!--[-->CSS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/Vue2+%E7%BB%84%E4%BB%B6.html" data-v-2f2cfafc><!--[-->Vue2+组件<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/Vue3+%E7%BB%84%E4%BB%B6.html" data-v-2f2cfafc><!--[-->Vue3+组件<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/React.html" data-v-2f2cfafc><!--[-->React<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>软件测试</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80.html" data-v-2f2cfafc><!--[-->测试基础<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95.html" data-v-2f2cfafc><!--[-->压力测试<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>多线程</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E5%B9%B6%E5%8F%91%20&amp;%20%E5%A4%9A%E7%BA%BF%E7%A8%8B/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-2f2cfafc><!--[-->基础篇<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E5%B9%B6%E5%8F%91%20&amp;%20%E5%A4%9A%E7%BA%BF%E7%A8%8B/%E5%B9%B6%E5%8F%91%E5%AE%8C%E5%96%84.html" data-v-2f2cfafc><!--[-->进阶篇<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>开发工具</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/Chrome.html" data-v-2f2cfafc><!--[-->Chrome<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/IDEA%E5%9F%BA%E7%A1%80.html" data-v-2f2cfafc><!--[-->IDEA基础<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/IDEA%E6%8F%92%E4%BB%B6.html" data-v-2f2cfafc><!--[-->IDEA插件<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/VS%20Code.html" data-v-2f2cfafc><!--[-->VS Code<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>消息中间件</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/RabbitMQ.html" data-v-2f2cfafc><!--[-->RabbitMQ<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/RocketMQ.html" data-v-2f2cfafc><!--[-->RocketMQ<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/Kafka.html" data-v-2f2cfafc><!--[-->Kafka<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/Canal.html" data-v-2f2cfafc><!--[-->Canal<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-0937f67c data-v-f6a63727><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-f6a63727 data-v-82b282f1 data-v-f3c41672><span class="check" data-v-f3c41672><span class="icon" data-v-f3c41672><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-82b282f1><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-82b282f1><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-0937f67c data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/renshuo123/renshuo123.github.io" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink no-icon" href="#" aria-label="twitter" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Twitter</title><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/></svg></a><a class="VPSocialLink no-icon" href="https://github.com/" aria-label target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg t="1676028692954" class="icon" ...</path></svg></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-0937f67c data-v-40855f84 data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-a7b5672a><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-a7b5672a><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><!----><!--[--><!--[--><!----><div class="group" data-v-40855f84><div class="item appearance" data-v-40855f84><p class="label" data-v-40855f84>Appearance</p><div class="appearance-action" data-v-40855f84><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-40855f84 data-v-82b282f1 data-v-f3c41672><span class="check" data-v-f3c41672><span class="icon" data-v-f3c41672><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-82b282f1><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-82b282f1><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><div class="group" data-v-40855f84><div class="item social-links" data-v-40855f84><div class="VPSocialLinks social-links-list" data-v-40855f84 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/renshuo123/renshuo123.github.io" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink no-icon" href="#" aria-label="twitter" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Twitter</title><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/></svg></a><a class="VPSocialLink no-icon" href="https://github.com/" aria-label target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg t="1676028692954" class="icon" ...</path></svg></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-0937f67c data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><!----></header><div class="VPLocalNav reached-top" data-v-255ec12d data-v-5cfd5582><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-5cfd5582><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-5cfd5582><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-5cfd5582>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-5cfd5582 data-v-18201f51><button data-v-18201f51>Return to top</button><!----></div></div><aside class="VPSidebar" data-v-255ec12d data-v-845b8fc6><div class="curtain" data-v-845b8fc6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-845b8fc6><span class="visually-hidden" id="sidebar-aria-label" data-v-845b8fc6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Java</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E6%96%B0%E7%89%B9%E6%80%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java新特性</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E9%9B%86%E5%90%88.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java集合</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java高级</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/Linux%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Linux基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/Linux%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Linux新特性</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/Shell.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Shell脚本</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/%E5%AE%9E%E7%94%A8%E8%84%9A%E6%9C%AC.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>实用脚本</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/%E8%BD%AF%E4%BB%B6%E9%83%A8%E7%BD%B2.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>软件部署</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Nginx</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E5%AE%9E%E6%88%98%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>实战篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E9%9D%A2%E8%AF%95%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>面试篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SSM</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/Maven.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Maven</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/Spring.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Spring</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/SpringMVC.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringMVC</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/SpringBatch.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringBatch</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SpringBoot</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E5%BA%94%E7%94%A8%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>应用篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E6%96%B0%E7%89%B9%E6%80%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>新特性</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E8%BF%90%E7%BB%B4&amp;%E5%8E%9F%E7%90%86.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>运维&原理</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SpringCloud</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringCloud</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E5%BF%85%E5%A4%87/Sentinel.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Sentinel</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SpringSecurity</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringSecurity/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringSecurity基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringSecurity/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringSecurity进阶篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringSecurity/%E9%AB%98%E7%BA%A7%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringSecurity高级篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Mybatis & MybatisPlus</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Mybatis&amp;MybatisPlus/Mybatis.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Mybatis</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Mybatis&amp;MybatisPlus/MybatisPlus.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MybatisPlus</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Mybatis&amp;MybatisPlus/JPA.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>JPA</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Git & ChatGPT</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Git.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Git</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Github.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Github</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/ChatGPT.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ChatGPT</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Jenkins.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Jenkins</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Netty.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Netty</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible has-active" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>数据库</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><section class="VPSidebarItem level-1 collapsible has-active" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>MySQL</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E4%BC%98%E5%8C%96.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL优化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E8%AE%BE%E8%AE%A1.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL设计</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E8%BF%90%E7%BB%B4.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL运维</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>分库分表</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>Redis</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E4%BC%98%E5%8C%96.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis优化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E5%8E%9F%E7%90%86.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis原理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis高级</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E5%AE%9E%E6%88%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis实战</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/%E6%9C%AC%E5%9C%B0%E7%BC%93%E5%AD%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>本地缓存</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>MongoDB</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MongoDB/%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MongoDB基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MongoDB/%E6%95%B4%E5%90%88.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MongoDB进阶</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>ElasticSearch</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/ElasticSearch/1%E3%80%81ES%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/ElasticSearch/3%E3%80%81ES%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES高级</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/influxdb.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>InfluxDB</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Neo4j.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Neo4j</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>高并发 & 秒杀 & 分布式</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E5%88%86%E5%B8%83%E5%BC%8F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>分布式理论</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E5%BF%85%E5%A4%87/%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>分布式锁</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E7%A7%92%E6%9D%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>秒杀</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E9%AB%98%E5%8F%AF%E7%94%A8.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>高可用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E9%AB%98%E5%B9%B6%E5%8F%91.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>高并发</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>云原生</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%BA%91%E5%8E%9F%E7%94%9F/Docker.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Docker</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%BA%91%E5%8E%9F%E7%94%9F/K8S.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>K8S</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>可视化 & 监控</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/%E7%9B%91%E6%8E%A7%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>监控基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/%E7%9B%91%E6%8E%A7%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>监控进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/%E5%8F%AF%E8%A7%86%E5%8C%96%E5%A4%A7%E5%B1%8F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>可视化大屏</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/Zabbix.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Zabbix</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>学前端</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>HTML+CSS</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/1%E3%80%81HTML+CSS/HTML%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>HTML基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/1%E3%80%81HTML+CSS/CSS%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>CSS基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/1%E3%80%81HTML+CSS/%E7%BD%91%E9%A1%B5%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>网页进阶</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>JS+TS</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/JS%20%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>JS基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/JS%20%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>JS进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/ES6%20%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES6基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/ES6%20%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES6进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/TypeScript.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>TS基础</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>NodeJS</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/4%E3%80%81Node/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Node基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/4%E3%80%81Node/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Node进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/4%E3%80%81Node/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目实战</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>Vue</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue3/Vue3%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Vue3进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue3/Vue3%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Vue3高级</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue3/Vue3%E6%96%B0%E8%AF%AD%E6%B3%95.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Vue3新语法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue2/Vue2%E9%A1%B9%E7%9B%AE.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目实战</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>小程序</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>小程序基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%BC%98%E5%8C%96.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>小程序优化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/uniapp.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>uniapp</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%A1%B9%E7%9B%AE.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目实战</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>计算机基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>数据结构</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>操作系统</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>设计模式</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>计算机网络</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/UML.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>UML</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E7%AE%97%E6%B3%95/LeetCode.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>LeetCode</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>项目实战</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>云尚办公</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E4%BA%91%E5%B0%9A%E5%8A%9E%E5%85%AC/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>小兔鲜</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E5%B0%8F%E5%85%94%E9%B2%9C/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E5%B0%8F%E5%85%94%E9%B2%9C/%E8%BF%9B%E9%98%B6%E7%AF%871.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇1</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E5%B0%8F%E5%85%94%E9%B2%9C/%E8%BF%9B%E9%98%B6%E7%AF%872.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇2</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>地图</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>苍穹外卖</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>黑马头条</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E8%BF%9B%E9%98%B6%E7%AF%872.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇2</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E9%AB%98%E7%BA%A7%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>高级篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E6%94%AF%E4%BB%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>支付</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%A1%B9%E7%9B%AE%E6%8E%A8%E8%8D%90.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目推荐</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0" data-v-845b8fc6 data-v-9b797284><!----><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/team.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>团队成员</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-255ec12d data-v-669faec9><div class="VPDoc has-sidebar has-aside" data-v-669faec9 data-v-6b87e69f><!--[--><!--]--><div class="container" data-v-6b87e69f><div class="aside" data-v-6b87e69f><div class="aside-curtain" data-v-6b87e69f></div><div class="aside-container" data-v-6b87e69f><div class="aside-content" data-v-6b87e69f><div class="VPDocAside" data-v-6b87e69f data-v-3f215769><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" data-v-3f215769 data-v-ff0f39c8><div class="content" data-v-ff0f39c8><div class="outline-marker" data-v-ff0f39c8></div><div class="outline-title" data-v-ff0f39c8>On this page</div><nav aria-labelledby="doc-outline-aria-label" data-v-ff0f39c8><span class="visually-hidden" id="doc-outline-aria-label" data-v-ff0f39c8> Table of Contents for current page </span><ul class="root" data-v-ff0f39c8 data-v-d0ee3533><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-6b87e69f><div class="content-container" data-v-6b87e69f><!--[--><!--]--><!----><main class="main" data-v-6b87e69f><div style="position:relative;" class="vp-doc _notebook_2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93_MySQL_MySQL%E6%A0%B8%E5%BF%83_%E8%BF%90%E7%BB%B4" data-v-6b87e69f><div><h1 id="日志⭐⭐" tabindex="-1">日志⭐⭐ <a class="header-anchor" href="#日志⭐⭐" aria-label="Permalink to &quot;日志⭐⭐&quot;">​</a></h1><p>日志是mysql数据库的重要组成部分，记录着数据库运行期间各种状态信息。mysql日志主要包括错误日志、查询日志、慢查询日志、事务日志、二进制日志几大类。作为开发，我们重点需要关注的是二进制日志(binlog)和事务日志(包括redo log和undo log)，本文接下来会详细介绍这三种日志。</p><h2 id="错误日志" tabindex="-1">错误日志 <a class="header-anchor" href="#错误日志" aria-label="Permalink to &quot;错误日志&quot;">​</a></h2><blockquote><p>错误日志是 MySQL 中最重要的日志之一，<strong>它记录了当 mysqld 启动和停止时，以及服务器在运行过程中发生任何严重错误时的相关信息</strong>。<strong>当数据库出现任何故障导致无法正常使用时，建议首先查看此日志</strong>。</p></blockquote><p>默认情况下，该日志功能是开启的，通过如下命令查找错误日志文件的存放路径。</p><blockquote><p>该日志是默认开启的，默认存放目录 /var/log/，默认的日志文件名为 mysqld.log</p></blockquote><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like &#39;%log_error%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221927339.png" alt="image-20220922192758261" style="zoom:80%;"><blockquote><p><strong>注意</strong>：错误日志中记录的可并非全是错误信息，像 MySQL 如何启动 <code>InnoDB</code> 的表空间文件、如何初始化自己的存储引擎，初始化 <code>buffer pool</code> 等等，这些也记录在错误日志文件中。</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">tail </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f mysqld</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">log</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221953596.png" alt="image-20220922195352467" style="zoom:80%;"><h2 id="二进制日志⭐" tabindex="-1">二进制日志⭐ <a class="header-anchor" href="#二进制日志⭐" aria-label="Permalink to &quot;二进制日志⭐&quot;">​</a></h2><blockquote><p>binlog<strong>用于记录数据库执行的写入性操作(不包括查询)信息，以二进制的形式保存在磁盘中</strong>。<strong>binlog是mysql的逻辑日志，并且由Server层进行记录，使用任何存储引擎的mysql数据库都会记录binlog日志</strong>。</p></blockquote><blockquote><ul><li>逻辑日志：可以简单理解为记录的就是sql语句。</li><li>物理日志：因为mysql数据最终是保存在数据页中的，物理日志记录的就是数据页变更。</li></ul></blockquote><blockquote><p>binlog是通过追加的方式进行写入的，可以通过max_binlog_size参数设置每个binlog文件的大小，当文件大小达到给定值之后，会生成新的文件来保存日志。</p></blockquote><h3 id="binlog-使用场景" tabindex="-1">binlog 使用场景 <a class="header-anchor" href="#binlog-使用场景" aria-label="Permalink to &quot;binlog 使用场景&quot;">​</a></h3><p>在实际应用中，binlog的主要使用场景有两个，分别是主从复制和数据恢复。</p><blockquote><ul><li>主从复制：<strong>在Master端开启binlog，然后将binlog发送到各个Slave端，Slave端重放binlog达到主从数据一致</strong></li><li>数据恢复：<strong>通过使用mysqlbinlog工具来恢复数据</strong>。</li></ul></blockquote><h3 id="binlog刷盘时机" tabindex="-1">binlog刷盘时机 <a class="header-anchor" href="#binlog刷盘时机" aria-label="Permalink to &quot;binlog刷盘时机&quot;">​</a></h3><blockquote><p>对于InnoDB存储引擎而言，只有在事务提交时才会记录biglog，此时记录还在内存中，那么biglog是什么时候刷到磁盘中的呢？mysql通过sync_binlog参数控制biglog的刷盘时机，取值范围是0-N：</p></blockquote><blockquote><ul><li>0：不去强制要求，由系统自行判断何时写入磁盘；</li><li>1：每次commit的时候都要将binlog写入磁盘；</li><li>N：每N个事务，才会将binlog写入磁盘。</li></ul></blockquote><blockquote><p>从上面可以看出，sync_binlog最安全的是设置是1，这也是MySQL 5.7.7之后版本的默认值。但是设置一个大一些的值可以提升数据库性能，因此实际情况下也可以将值适当调大，牺牲一定的一致性来获取更好的性能。</p></blockquote><h3 id="开启二进制日志" tabindex="-1">开启二进制日志 <a class="header-anchor" href="#开启二进制日志" aria-label="Permalink to &quot;开启二进制日志&quot;">​</a></h3><blockquote><p>在MySQL8版本中，默认二进制日志是开启着的，以下是mysql5.7配置开启</p></blockquote><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">server-id=202</span></span>
<span class="line"><span style="color:#A6ACCD;">log-bin=mysql-bin</span></span>
<span class="line"><span style="color:#A6ACCD;">binlog-ignore-db = mysql,information_schema</span></span></code></pre></div><p>加入后，重启mysql服务，查看是否开启</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like &#39;%log_bin%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221955877.png" alt="image-20220922195508824" style="zoom:80%;"><p>进入/var/lib/mysql目录查看</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221956080.png" alt="image-20220922195607997" style="zoom:80%;"><h3 id="binlog日志格式⭐" tabindex="-1">binlog日志格式⭐ <a class="header-anchor" href="#binlog日志格式⭐" aria-label="Permalink to &quot;binlog日志格式⭐&quot;">​</a></h3><p>binlog日志有三种格式，分别为 STATMENT、ROW和MIXED。</p><blockquote><p>在 MySQL 5.7.7之前，默认的格式是STATEMENT，MySQL 5.7.7之后，默认值是ROW。通过binlog-format指定格式</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221957855.png" alt="image-20220922195734784" style="zoom:80%;"><h4 id="statement-模式" tabindex="-1">STATEMENT 模式 <a class="header-anchor" href="#statement-模式" aria-label="Permalink to &quot;STATEMENT 模式&quot;">​</a></h4><blockquote><p>内容：binlog 只会记录可能引起数据变更的 sql 语句，对数据进行修改的SQL都会记录在日志文件中</p><p>优势：该模式下，因为没有记录实际的数据，所以日志量和 IO 都消耗很低，性能是最优的</p><p>劣势：但有些操作并不是确定的，比如 uuid() 函数会随机产生唯一标识，当依赖 binlog 回放时，该操作生成的数据与原数据必然是不同的，此时可能造成无法预料的后果。</p></blockquote><h4 id="row-模式" tabindex="-1">ROW 模式 <a class="header-anchor" href="#row-模式" aria-label="Permalink to &quot;ROW 模式&quot;">​</a></h4><blockquote><p>内容：基于行的日志记录，binlog 会<strong>记录每次操作的源数据与修改后的目标数据</strong>，默认就是该模式</p><p>优势：<strong>可以绝对精准的还原，从而保证了数据的安全与可靠，并且复制和数据恢复过程可以是并发进行的</strong></p><p>劣势：<strong>缺点在于 binlog 体积会非常大，同时，对于修改记录多、字段长度大的操作来说，记录时性能消耗会很严重。阅读的时候也需要特殊指令来进行读取数据</strong>。<strong>会产生大量的日志，尤其是alter table的时候会让日志暴涨</strong></p></blockquote><h4 id="mixed-模式" tabindex="-1">MIXED 模式 <a class="header-anchor" href="#mixed-模式" aria-label="Permalink to &quot;MIXED 模式&quot;">​</a></h4><blockquote><p>内容：是对上述STATEMENT 跟 ROW 两种模式的混合使用。</p><p>细节：对于绝大部分操作，都使用 STATEMENT 来进行 binlog 的记录，只有以下操作使用 ROW 来实现：表的存储引擎为 NDB，使用了uuid() 等不确定函数，使用了 insert delay 语句，使用了临时表</p></blockquote><h4 id="binlog格式查看-修改" tabindex="-1">binlog格式查看 &amp; 修改 <a class="header-anchor" href="#binlog格式查看-修改" aria-label="Permalink to &quot;binlog格式查看 &amp; 修改&quot;">​</a></h4><h5 id="查看日志格式" tabindex="-1">查看日志格式 <a class="header-anchor" href="#查看日志格式" aria-label="Permalink to &quot;查看日志格式&quot;">​</a></h5><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like &#39;%binlog_format%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221958233.png" alt="image-20220922195808183" style="zoom:80%;"><h5 id="修改日志格式" tabindex="-1">修改日志格式 <a class="header-anchor" href="#修改日志格式" aria-label="Permalink to &quot;修改日志格式&quot;">​</a></h5><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">binlog_format</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">STATEMENT</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl restart mysqld</span></span></code></pre></div><p>重启服务，再次查询format，可以发现已经由ROW改成STATEMENT</p><h3 id="binlog日志操作⭐" tabindex="-1">binlog日志操作⭐ <a class="header-anchor" href="#binlog日志操作⭐" aria-label="Permalink to &quot;binlog日志操作⭐&quot;">​</a></h3><h4 id="日志查看" tabindex="-1">日志查看 <a class="header-anchor" href="#日志查看" aria-label="Permalink to &quot;日志查看&quot;">​</a></h4><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">binary</span><span style="color:#A6ACCD;"> logs;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222004335.png" alt="image-20220922200458281" style="zoom:80%;"><p>由于日志是以二进制方式存储的，<strong>不能直接读取</strong>，需要通过二进制日志查询工具 mysqlbinlog 来查看</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220205120832788.png" alt="image-20220205120832788" style="zoom:80%;"><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql</span></span>
<span class="line"><span style="color:#FFCB6B;">mysqlbinlog</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-v</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">mysql-bin.000036</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222001547.png" alt="image-20220922200126439" style="zoom:80%;"><h4 id="日志删除" tabindex="-1">日志删除 <a class="header-anchor" href="#日志删除" aria-label="Permalink to &quot;日志删除&quot;">​</a></h4><h5 id="手动删除" tabindex="-1">手动删除 <a class="header-anchor" href="#手动删除" aria-label="Permalink to &quot;手动删除&quot;">​</a></h5><p>对于比较繁忙的业务系统，每天生成的binlog数据巨大，如果长时间不清除，将会占用大量磁盘空间。</p><p>可以通过以下几种方式清理日志：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220205120915414.png" alt="image-20220205120915414" style="zoom:80%;"><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">-- 删除它编号之前的日志(不包含它本身)</span></span>
<span class="line"><span style="color:#A6ACCD;">purge master logs to &#39;mysql-bin.000037&#39;;</span></span>
<span class="line"><span style="color:#A6ACCD;">-- 删除全部</span></span>
<span class="line"><span style="color:#A6ACCD;">reset master ;</span></span></code></pre></div><p>再次查看</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">binary</span><span style="color:#A6ACCD;"> logs;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222009318.png" alt="image-20220922200910265" style="zoom:80%;"><h5 id="自动删除" tabindex="-1">自动删除 <a class="header-anchor" href="#自动删除" aria-label="Permalink to &quot;自动删除&quot;">​</a></h5><blockquote><p>也可以在mysql的配置文件中配置二进制日志的过期时间，设置了之后，二进制日志过期会自动删除。一般来说开启bin log都会给日志文件设置过期时间（默认永久保存），要不然日志的体量会非常庞大。</p></blockquote><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 修改它就能决定二进制日志的保存时间，0表示不删除，604800表示3600*24*7，7天时间</span></span>
<span class="line"><span style="color:#F07178;">binlog_expire_logs_seconds</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">604800</span></span></code></pre></div><p>重启服务后，查询</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl restart mysqld</span></span></code></pre></div><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like &#39;%binlog_expire_logs_seconds%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222014969.png" alt="image-20220922201408917" style="zoom:80%;"><h2 id="查询日志" tabindex="-1">查询日志 <a class="header-anchor" href="#查询日志" aria-label="Permalink to &quot;查询日志&quot;">​</a></h2><blockquote><p>一般查询日志（general query log）：用来记录用户的<strong>所有</strong>操作，包括客户端何时连接了服务器、客户端发送的所有SQL以及其他事件，比如 MySQL服务启动和关闭等等。MySQL服务器会按照它接收到语句的先后顺序写入日志文件。由于一般查询日志记录的内容过于详细，开启后 Log 文件的体量会非常庞大，所以出于对性能的考虑，默认情况下，该日志功能是关闭的，通常会在排查故障需获得详细日志的时候才会临时开启。</p></blockquote><p>我们可以通过以下命令查看一般查询日志是否开启，命令如下：</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">general_log</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222015381.png" alt="image-20220922201517332" style="zoom:80%;"><p>下边开启一般查询日志并查看日志存放的位置。</p><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 该选项用来开启查询日志,可选值0和1；0代表关闭，1代表开启</span></span>
<span class="line"><span style="color:#F07178;">general_log</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设置日志的文件名,如果没有指定,默认的文件名为host_name.log</span></span>
<span class="line"><span style="color:#F07178;">general_log_file</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql_query.log</span></span></code></pre></div><p>重启服务，进行查询看是否开启</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl restart mysqld</span></span>
<span class="line"><span style="color:#A6ACCD;">show variables like &#39;%general%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220205122545081.png" alt="image-20220205122545081" style="zoom:80%;"><p>生成文件位置：/var/lib/mysql</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">tail </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f mysql_query</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">log</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222024518.png" alt="image-20220922202440431" style="zoom:80%;"><blockquote><p>开启了查询日志之后，在MySQL的数据存放目录，也就是 /var/lib/mysql/ 目录下就会出现mysql_query.log 文件。</p><p>之后所有的客户端的增删改查操作都会记录在该日志文件之中，长时间运行后，该日志文件将会非常大。</p></blockquote><h2 id="慢查询日志" tabindex="-1">慢查询日志 <a class="header-anchor" href="#慢查询日志" aria-label="Permalink to &quot;慢查询日志&quot;">​</a></h2><blockquote><p>慢查询日志（<strong><code>slow query log</code></strong>）: 用来记录在 MySQL 中执行时间超过指定时间的查询语句，在 SQL 优化过程中会经常使用到。通过慢查询日志，我们可以查找出哪些查询语句的执行效率低，耗时严重。</p></blockquote><blockquote><p>出于性能方面的考虑，一般只有在排查慢SQL、调试参数时才会开启，默认情况下，慢查询日志功能是关闭的。可以通过以下命令查看是否开启慢查询日志：</p></blockquote><blockquote><p>慢查询日志记录了所有执行时间超过参数 long_query_time 设置值并且扫描记录数不小min_examined_row_limit的所有的SQL语句的日志，默认未开启。long_query_time 默认为 10 秒，最小为 0， 精度可以到微秒。</p></blockquote><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%slow_query%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221946189.png" alt="image-20220922194652140" style="zoom:80%;"><p>在my.cnf中开启慢日志</p><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">slow-query-log</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1</span></span>
<span class="line"><span style="color:#F07178;">slow_query_log_file</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">slow.log</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 默认慢查询日志为10s，这里改小，方便测试</span></span>
<span class="line"><span style="color:#F07178;">long_query_time</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">0.00001</span></span></code></pre></div><p>上边提到超过 <code>指定时间</code> 的查询语句才算是慢查询，那么这个时间阈值又是多少嘞？我们通过 <code>long_query_time</code> 参数来查看一下，发现默认是 10 秒。</p><blockquote><p>慢查询日志目录：/var/lib/mysql</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">tail </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">slow</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">log</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222034518.png" alt="image-20220922203410446" style="zoom:80%;"><blockquote><p>默认情况下，不会记录管理语句，也不会记录不使用索引进行查找的查询。可以使用log_slow_admin_statements和 更改此行为 log_queries_not_using_indexes，如下所述。</p></blockquote><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 记录执行较慢的管理语句</span></span>
<span class="line"><span style="color:#F07178;">log_slow_admin_statements</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 记录执行较慢的未使用索引的语句</span></span>
<span class="line"><span style="color:#F07178;">log_queries_not_using_indexes</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1</span></span></code></pre></div><blockquote><p>上述所有的参数配置完成之后，都需要重新启动MySQL服务器才可以生效。</p></blockquote><h2 id="注意事项" tabindex="-1">注意事项 <a class="header-anchor" href="#注意事项" aria-label="Permalink to &quot;注意事项&quot;">​</a></h2><h3 id="修改日志时区" tabindex="-1">修改日志时区 <a class="header-anchor" href="#修改日志时区" aria-label="Permalink to &quot;修改日志时区&quot;">​</a></h3><blockquote><p>默认 UTC 这样会导致日志中记录的时间比中国这边的慢，导致查看日志不方便。修改为 SYSTEM 就能解决问题</p></blockquote><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%log_timestamps%</span><span style="color:#89DDFF;">&#39;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221936725.png" alt="image-20220922193641672" style="zoom:80%;"><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 在my.ini中写入如下，跟随系统时间，重启服务，即可发现时间正确</span></span>
<span class="line"><span style="color:#F07178;">log_timestamps</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">SYSTEM</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl restart mysqld</span></span></code></pre></div><h3 id="redo-log与binlog区别" tabindex="-1">redo log与binlog区别 <a class="header-anchor" href="#redo-log与binlog区别" aria-label="Permalink to &quot;redo log与binlog区别&quot;">​</a></h3><blockquote><p>由binlog和redo log的区别可知：binlog日志只用于归档，只依靠binlog是没有crash-safe能力的。但只有redo log也不行，因为redo log是InnoDB特有的，且日志上的记录落盘后会被覆盖掉。因此需要binlog和redo log二者同时记录，才能保证当数据库发生宕机重启时，数据不会丢失。</p></blockquote><h1 id="配置文件" tabindex="-1">配置文件 <a class="header-anchor" href="#配置文件" aria-label="Permalink to &quot;配置文件&quot;">​</a></h1><p><a href="https://developer.aliyun.com/article/822935" target="_blank" rel="noreferrer">MySQL 配置文件 my.cnf / my.ini 逐行详解-阿里云开发者社区 (aliyun.com)</a></p><blockquote><p>Windows 和 Linux 下的 MySQL 配置文件的名字和存放位置都是不同的，WIndows 下 MySQL 配置文件是 <code>my.ini</code> 存放在 MySQL 安装目录的根目录下；Linux 下 MySQL 配置文件是 <code>my.cnf</code> 存放在 <code>/etc/my.cnf</code>、<code>/etc/mysql/my.cnf</code>。我们也可以通过 <code>find</code> 命令进行查找。</p></blockquote><blockquote><p>另外要注意的是，通过 rpm 命令安装的 MySQL 是没有 <code>/etc/my.cnf</code> 文件的，如果需要配置 MySQL，可以在<code>/etc/my.cnf</code>新建配置文件，然后把本文的配置信息复制到文件中即可。</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 查看配置文件位置</span></span>
<span class="line"><span style="color:#FFCB6B;">mysql</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--help</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">grep</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">cnf</span><span style="color:#89DDFF;">&#39;</span></span></code></pre></div><h2 id="client" tabindex="-1">[client] <a class="header-anchor" href="#client" aria-label="Permalink to &quot;[client]&quot;">​</a></h2><blockquote><p>在MySQL的配置文件my.cnf中，[client]部分是用于配置客户端连接MySQL服务器的参数，[mysqld]部分则是用于配置MySQL服务器本身的参数。</p></blockquote><blockquote><p>在[client]部分中，port参数指定了客户端连接MySQL服务器使用的端口号，即连接MySQL服务器的网络端口号。这个端口号通常是3306。</p></blockquote><blockquote><p>在[mysqld]部分中，port参数指定了MySQL服务器监听的端口号，即MySQL服务器绑定的网络端口号。当客户端需要连接MySQL服务器时，就会使用这个端口号来连接。可以通过修改这个参数来更改MySQL服务器监听的端口号。</p></blockquote><blockquote><p>因此，这两个port参数虽然名字相同，但是含义不同，分别用于配置客户端连接MySQL服务器的端口号和MySQL服务器监听的端口号。</p></blockquote><p>客户端设置。当前为客户端默认参数</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">port</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3306</span></span></code></pre></div><p>默认连接端口为 <code>3306</code></p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">socket</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/tmp/mysql.sock</span></span></code></pre></div><p>本地连接的 <code>socket</code> 套接字</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">default_character_set</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">utf8</span></span></code></pre></div><p>设置字符集，通常使用 <code>uft8</code> 即可</p><h2 id="mysqld-safe" tabindex="-1">[mysqld_safe] <a class="header-anchor" href="#mysqld-safe" aria-label="Permalink to &quot;[mysqld_safe]&quot;">​</a></h2><p><code>mysqld_safe</code> 是服务器端工具，用于启动 <code>mysqld</code>，也是 <code>mysqld</code> 的守护进程。当 mysql 被 kill 时，<code>mysqld_safe</code> 负责重启启动它。</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">open_files_limit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">8192</span></span></code></pre></div><p>此为 MySQL 打开的文件描述符限制，它是 MySQL 中的一个全局变量且不可动态修改。它控制着 mysqld 进程能使用的最大文件描述符数量。默认最小值为 1024</p><p>需要注意的是这个变量的值并不一定是你在这里设置的值，mysqld 会在系统允许的情况下尽量取最大值。</p><p>当 <code>open_files_limit</code> 没有被配置时，比较 <code>max_connections*5</code> 和 <code>ulimit -n</code> 的值，取最大值</p><p>当 <code>open_file_limit</code> 被配置时，比较 <code>open_files_limit</code> 和 <code>max_connections*5</code> 的值，取最大值</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">user</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql</span></span></code></pre></div><p>用户名，错误 log 记录文件</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">log-error  = error.log</span></span></code></pre></div><h2 id="mysqld" tabindex="-1">[mysqld] <a class="header-anchor" href="#mysqld" aria-label="Permalink to &quot;[mysqld]&quot;">​</a></h2><p>服务端基本配置</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">port = 3306</span></span></code></pre></div><p>mysqld 服务端监听端口</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">socket = /tmp/mysql.sock</span></span></code></pre></div><p>MySQL 客户端程序和服务器之间的本地通讯指定一个套接字文件</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">max_allowed_packet  = 16M</span></span></code></pre></div><p>允许最大接收数据包的大小，防止服务器发送过大的数据包。</p><p>当发出长查询或 mysqld 返回较大结果时，mysqld 才会分配内存，所以增大这个值风险不大，默认 16M，也可以根据需求改大，但太大会有溢出风险。取较小值是一种安全措施，避免偶然出现但大数据包导致内存溢出。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">default_storage_engine = InnoDB</span></span></code></pre></div><p>创建数据表时，默认使用的存储引擎。这个变量还可以通过 <code>–default-table-type</code> 进行设置</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">max_connections  = 512</span></span></code></pre></div><p>最大连接数，当前服务器允许多少并发连接。默认为 100，一般设置为小于 1000 即可。太高会导致内存占用过多，MySQL 服务器会卡死。作为参考，小型站设置 100 - 300</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">max_user_connections = 50</span></span></code></pre></div><p>用户最大的连接数，默认值为 50 一般使用默认即可。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">thread_cache_size = 64</span></span></code></pre></div><p>线程缓存，用于缓存空闲的线程。这个数表示可重新使用保存在缓存中的线程数，当对方断开连接时，如果缓存还有空间，那么客户端的线程就会被放到缓存中，以便提高系统性能。我们可根据物理内存来对这个值进行设置，对应规则 1G 为 8；2G 为 16；3G 为 32；4G 为 64 等。</p><h2 id="核心参数" tabindex="-1">核心参数 <a class="header-anchor" href="#核心参数" aria-label="Permalink to &quot;核心参数&quot;">​</a></h2><div class="language-properties"><button title="Copy Code" class="copy"></button><span class="lang">properties</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">innodb_buffer_pool </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：缓冲池位于主内存中，InnoDB用它来缓存被访问过的表和索引文件，使常用数据可以直接在内存中被处理，从而提升处理速度；</span></span>
<span class="line"><span style="color:#A6ACCD;">innodb_buffer_pool_instance</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：MySQL5.6.6之后可以调整为多个。表示InnoDB缓冲区可以被划分为多个区域，也可以理解为把innodb_buffer_pool划分为多个实例，可以提高并发性，避免在高并发环境下，出现内存的争用问题；</span></span>
<span class="line"><span style="color:#A6ACCD;">innodb_data_file_path</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：该参数可以指定系统表空间文件的路径和ibdata1文件的大小。默认大小是10MB，这里建议调整为1GB</span></span>
<span class="line"><span style="color:#A6ACCD;">transaction_isolation</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：MySQL数据库的事务隔离级别有四种，分别为READ-UNCOMMITTED、READ-COMMITTED、REPEATABLE-READ和SERIALIZABLE。默认采用REPEATABLE-READ（可重复读）</span></span>
<span class="line"><span style="color:#A6ACCD;">innodb_log_buffer_size</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：是日志缓冲的大小，InnoDB改变数据的时候，它会把这次改动的记录先写到日志缓冲中</span></span>
<span class="line"><span style="color:#A6ACCD;">innodb_log_file_size</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：是指Redo log日志的大小，该值设置不宜过大也不宜过小，如果设置太大，实例恢复的时候需要较长时间，如果设置太小，会造成redo log 切换频繁，产生无用的I/O消耗，影响数据库性能</span></span>
<span class="line"><span style="color:#A6ACCD;">innodb_log_files_in_group</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：redo log文件组中日志文件的数量，默认情况下至少有2个</span></span>
<span class="line"><span style="color:#A6ACCD;">max_connections</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 该参数代表MySQL数据库的最大连接数</span></span>
<span class="line"><span style="color:#A6ACCD;">expire_logs_days</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：该参数代表binlog的过期时间，单位是天</span></span>
<span class="line"><span style="color:#A6ACCD;">slow_query_log</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：慢查询日志的开关，该参数等于1代表开启慢查询</span></span>
<span class="line"><span style="color:#A6ACCD;">long_query_time</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：慢查询的时间，某条SQL语句超过该参数设置的时间，就会记录到慢查询日志中。单位是秒</span></span>
<span class="line"><span style="color:#A6ACCD;">binlog_format</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：该参数代表二进制日志的格式。binlog格式有三种statement、row和mixed。生产环境中使用row这种格式更安全，不会出现跨库复制丢数据的情况</span></span>
<span class="line"><span style="color:#A6ACCD;">lower_case_table_names</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：表名是否区分大小的参数。默认是值为0。0代表区分大小写，1代表不区分大小写，以小写存储</span></span>
<span class="line"><span style="color:#A6ACCD;">interactive_timeout</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：是服务器关闭交互式连接前等待活动的时间,默认是28800s（8小时）</span></span>
<span class="line"><span style="color:#A6ACCD;">wait_timeout</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：是服务器关闭非交互式连接之前等待活动的时间，默认是28800s（8小时）</span></span>
<span class="line"><span style="color:#A6ACCD;">innodb_flush_method</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：这个参数影响InnoDB数据文件，redo log文件的打开刷写模式</span></span>
<span class="line"><span style="color:#A6ACCD;">log_queries_not_using_indexes</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注：如果运行的SQL语句没有使用索引，则MySQL数据库同样会将这条SQL语句记录到慢查询日志文件中</span></span></code></pre></div><h2 id="配置文件优化" tabindex="-1">配置文件优化 <a class="header-anchor" href="#配置文件优化" aria-label="Permalink to &quot;配置文件优化&quot;">​</a></h2><div class="language-properties"><button title="Copy Code" class="copy"></button><span class="lang">properties</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">###########################################################################</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## my.cnf for MySQL 8.0.x                                                  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 本配置参考  https://imysql.com/my-cnf-wizard.html                         </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 注意：                                                                   </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">##   (1)本配置假设物理服务器内存为 16G，总表数量在300之内，中小型企业业务          </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">##   (2)请根据实际情况作调整部分参数                                          </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">##   (3)本人不对这些建议结果负相应责任 ，仅作参考                             </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">###########################################################################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">###########################################################################</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">##客户端参数配置</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">###########################################################################</span></span>
<span class="line"><span style="color:#89DDFF;">[client]</span></span>
<span class="line"><span style="color:#F07178;">port</span><span style="color:#A6ACCD;">	</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 3306</span></span>
<span class="line"><span style="color:#F07178;">socket</span><span style="color:#A6ACCD;">	</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">/var/lib/mysql/mysqld.sock</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">[mysql]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#prompt=&quot;\u@mysqldb \R:\m:\s [\d]&gt; &quot;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#关闭自动补全sql命令功能</span></span>
<span class="line"><span style="color:#A6ACCD;">no-auto-rehash</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">###########################################################################</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">##服务端参数配置</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">###########################################################################</span></span>
<span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#F07178;">port</span><span style="color:#A6ACCD;">	</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 3306</span></span>
<span class="line"><span style="color:#F07178;">datadir</span><span style="color:#A6ACCD;">	</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /var/lib/mysql</span></span>
<span class="line"><span style="color:#F07178;">socket</span><span style="color:#A6ACCD;">	</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /var/lib/mysql/mysqld.sock</span></span>
<span class="line"><span style="color:#F07178;">log-error</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /var/lib/mysql/error.log</span></span>
<span class="line"><span style="color:#F07178;">pid-file</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /var/lib/mysql/mysqld.pid</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#只能用IP地址检查客户端的登录，不用主机名</span></span>
<span class="line"><span style="color:#F07178;">skip_name_resolve</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#若你的MySQL数据库主要运行在境外，请务必根据实际情况调整本参数</span></span>
<span class="line"><span style="color:#F07178;">default_time_zone</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">+8:00</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#数据库默认字符集, 主流字符集支持一些特殊表情符号（特殊表情符占用4个字节）</span></span>
<span class="line"><span style="color:#F07178;">character-set-server</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> utf8mb4</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#数据库字符集对应一些排序等规则，注意要和character-set-server对应</span></span>
<span class="line"><span style="color:#F07178;">collation-server</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> utf8mb4_general_ci</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#设置client连接mysql时的字符集,防止乱码</span></span>
<span class="line"><span style="color:#F07178;">init_connect</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">SET NAMES utf8mb4</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#是否对sql语句大小写敏感，1表示不敏感</span></span>
<span class="line"><span style="color:#F07178;">lower_case_table_names</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 执行sql的模式，规定了sql的安全等级, 暂时屏蔽，my.cnf文件中配置报错</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#sql_mode = STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#事务隔离级别，默认为可重复读，mysql默认可重复读级别（此级别下可能参数很多间隙锁，影响性能）</span></span>
<span class="line"><span style="color:#F07178;">transaction_isolation</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> READ-COMMITTED</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#TIMESTAMP如果没有显示声明NOT NULL，允许NULL值</span></span>
<span class="line"><span style="color:#F07178;">explicit_defaults_for_timestamp</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> true</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#它控制着mysqld进程能使用的最大文件描述(FD)符数量。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#需要注意的是这个变量的值并不一定是你设定的值，mysqld会在系统允许的情况下尽量获取更多的FD数量</span></span>
<span class="line"><span style="color:#F07178;">open_files_limit</span><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 65535</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#最大连接数</span></span>
<span class="line"><span style="color:#F07178;">max_connections</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 300</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#最大错误连接数</span></span>
<span class="line"><span style="color:#F07178;">max_connect_errors</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 600</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#在MySQL暂时停止响应新请求之前的短时间内多少个请求可以被存在堆栈中</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#官方建议 back_log = 50 + (max_connections / 5),封顶数为65535,默认值= max_connections</span></span>
<span class="line"><span style="color:#F07178;">back_log</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 110</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># The number of open tables for all threads</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># For example, for 200 concurrent running connections, specify a table cache size of at least 200 * N, </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># where N is the maximum number of tables per join in any of the queries which you execute. </span></span>
<span class="line"><span style="color:#F07178;">table_open_cache</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 600</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># The number of table definitions that can be stored in the definition cache </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MIN(400 + table_open_cache / 2, 2000)</span></span>
<span class="line"><span style="color:#F07178;">table_definition_cache</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 700</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 为了减少会话之间的争用，可以将opentables缓存划分为table_open_cache/table_open_cache_instances个小缓存</span></span>
<span class="line"><span style="color:#F07178;">table_open_cache_instances</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 64</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 每个线程的堆栈大小 如果线程堆栈太小，则会限制执行复杂SQL语句</span></span>
<span class="line"><span style="color:#F07178;">thread_stack</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 512K</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 禁止外部系统锁</span></span>
<span class="line"><span style="color:#F07178;">external-locking</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> FALSE</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#SQL数据包发送的大小，如果有BLOB对象建议修改成1G</span></span>
<span class="line"><span style="color:#F07178;">max_allowed_packet</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 128M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#order by 或group by 时用到</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#建议先调整为4M，后期观察调整</span></span>
<span class="line"><span style="color:#F07178;">sort_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#inner left right join时用到</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#建议先调整为4M，后期观察调整</span></span>
<span class="line"><span style="color:#F07178;">join_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># How many threads the server should cache for reuse.</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果您的服务器每秒达到数百个连接，则通常应将thread_cache_size设置得足够高，以便大多数新连接使用缓存线程</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># default value = 8 + ( max_connections / 100) 上限为100</span></span>
<span class="line"><span style="color:#F07178;">thread_cache_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 20</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#MySQL连接闲置超过一定时间后(单位：秒)将会被强行关闭</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#MySQL默认的wait_timeout  值为8个小时, interactive_timeout参数需要同时配置才能生效</span></span>
<span class="line"><span style="color:#F07178;">interactive_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1800</span></span>
<span class="line"><span style="color:#F07178;">wait_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1800</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#Metadata Lock最大时长（秒）， 一般用于控制 alter操作的最大时长sine mysql5.6</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#执行 DML操作时除了增加innodb事务锁外还增加Metadata Lock，其他alter（DDL）session将阻塞</span></span>
<span class="line"><span style="color:#F07178;">lock_wait_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 3600</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#内部内存临时表的最大值。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#比如大数据量的group by ,order by时可能用到临时表，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#超过了这个值将写入磁盘，系统IO压力增大</span></span>
<span class="line"><span style="color:#F07178;">tmp_table_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 64M</span></span>
<span class="line"><span style="color:#F07178;">max_heap_table_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 64M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- 慢SQL日志记录 开始 --##########################################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#是否启用慢查询日志，1为启用，0为禁用  </span></span>
<span class="line"><span style="color:#F07178;">slow_query_log</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#记录系统时区</span></span>
<span class="line"><span style="color:#F07178;">log_timestamps</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> SYSTEM</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#指定慢查询日志文件的路径和名字</span></span>
<span class="line"><span style="color:#F07178;">slow_query_log_file</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /var/lib/mysql/slow.log</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#慢查询执行的秒数，必须达到此值可被记录</span></span>
<span class="line"><span style="color:#F07178;">long_query_time</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 5</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#将没有使用索引的语句记录到慢查询日志  </span></span>
<span class="line"><span style="color:#F07178;">log_queries_not_using_indexes</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#设定每分钟记录到日志的未使用索引的语句数目，超过这个数目后只记录语句数量和花费的总时间  </span></span>
<span class="line"><span style="color:#F07178;">log_throttle_queries_not_using_indexes</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 60</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#对于查询扫描行数小于此参数的SQL，将不会记录到慢查询日志中</span></span>
<span class="line"><span style="color:#F07178;">min_examined_row_limit</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 5000</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#记录执行缓慢的管理SQL，如alter table,analyze table, check table, create index, drop index, optimize table, repair table等。  </span></span>
<span class="line"><span style="color:#F07178;">log_slow_admin_statements</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#作为从库时生效, 从库复制中如何有慢sql也将被记录</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#对于ROW格式binlog，不管执行时间有没有超过阈值，都不会写入到从库的慢查询日志</span></span>
<span class="line"><span style="color:#F07178;">log_slow_slave_statements</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- 慢SQL日志记录 结束 --##########################################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- Bin-Log设置 开始 --############################################</span></span>
<span class="line"><span style="color:#F07178;">server-id</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 110</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#开启bin log 功能</span></span>
<span class="line"><span style="color:#F07178;">log-bin</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql-bin</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#binlog 记录内容的方式，记录被操作的每一行</span></span>
<span class="line"><span style="color:#F07178;">binlog_format</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> ROW</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#对于binlog_format = ROW模式时，FULL模式可以用于误操作后的flashBack。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#如果设置为MINIMAL，则会减少记录日志的内容，只记录受影响的列，但对于部分update无法flashBack</span></span>
<span class="line"><span style="color:#F07178;">binlog_row_image</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> FULL</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#bin log日志保存的天数</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#如果 binlog_expire_logs_seconds 选项也存在则 expire_logs_days 选项无效</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#expire_logs_days 已经被标注为过期参数</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#expire_logs_days = 7</span></span>
<span class="line"><span style="color:#F07178;">binlog_expire_logs_seconds</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1209600</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#master status and connection information输出到表mysql.slave_master_info中</span></span>
<span class="line"><span style="color:#F07178;">master_info_repository</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> TABLE</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#the slave&#39;s position in the relay logs输出到表mysql.slave_relay_log_info中</span></span>
<span class="line"><span style="color:#F07178;">relay_log_info_repository</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> TABLE</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#作为从库时生效, 想进行级联复制，则需要此参数</span></span>
<span class="line"><span style="color:#A6ACCD;">log_slave_updates</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#作为从库时生效, 中继日志relay-log可以自我修复</span></span>
<span class="line"><span style="color:#F07178;">relay_log_recovery</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#作为从库时生效, 主从复制时忽略的错误</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#如果在备份过程中执行ddl操作，从机需要从主机的备份恢复时可能会异常，从而导致从机同步数据失败</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#如果对数据完整性要求不是很严格，那么这个选项确实可以减轻维护的成本</span></span>
<span class="line"><span style="color:#F07178;">slave_skip_errors</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> ddl_exist_errors</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#####RedoLog日志 和 binlog日志的写磁盘频率设置 BEGIN ###################################</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># RedoLog日志（用于增删改事务操作） +  binlog日志（用于归档，主从复制）</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 为什么会有两份日志呢？ </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 因为最开始MySQL没有 InnoDB 引擎,自带MyISAM引擎没有 crash-safe能力，binlog日志只用于归档</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># InnoDB 引擎是另一个公司以插件形式引入MySQL的，采用RedoLog日志来实现 crash-safe 能力</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># redo log 的写入（即事务操作）拆成两阶段提交（2PC）：prepare阶段 和 commit阶段</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#(事务步骤1) 执行commit命令，InnoDB redo log 写盘，然后告知Mysql执行器:[你可以写binlog了，且一并提交事务]，事务进入 prepare 状态</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#(事务步骤2) 如果前面 prepare 成功，Mysql执行器生成 binlog 并且将binlog日志写盘</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#(事务步骤3) 如果binlog写盘成功，Mysql执行器一并调用InnoDB引擎的提交事务接口，事务进入 commit 状态，操作完成，事务结束</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#参数设置成 1，每次事务都直接持久化到磁盘</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#参数设置成 0，mysqld进程的崩溃会导致上一秒钟所有事务数据的丢失。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#参数设置成 2，只有在操作系统崩溃或者系统掉电的情况下，上一秒钟所有事务数据才可能丢失。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#即便都设置为1，服务崩溃或者服务器主机crash，Mysql也可能丢失但最多一个事务</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#控制 redolog 写磁盘频率 默认为1</span></span>
<span class="line"><span style="color:#F07178;">innodb_flush_log_at_trx_commit</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#控制 binlog 写磁盘频率</span></span>
<span class="line"><span style="color:#F07178;">sync_binlog</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#####RedoLog日志 和 binlog日志的写磁盘频率设置 END #####################################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#一般数据库中没什么大的事务，设成1~2M，默认32kb</span></span>
<span class="line"><span style="color:#F07178;">binlog_cache_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#binlog 能够使用的最大cache 内存大小</span></span>
<span class="line"><span style="color:#F07178;">max_binlog_cache_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 2G</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#单个binlog 文件大小 默认值是1GB</span></span>
<span class="line"><span style="color:#F07178;">max_binlog_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1G</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#开启GTID复制模式</span></span>
<span class="line"><span style="color:#F07178;">gtid_mode</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> on</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#强制gtid一致性，开启后对于create table ... select ...或 CREATE TEMPORARY TABLE 将不被支持</span></span>
<span class="line"><span style="color:#F07178;">enforce_gtid_consistency</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#解决部分无主键表导致的从库复制延迟问题</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#其基本思路是对于在一个ROWS EVENT中的所有前镜像收集起来，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#然后在一次扫描全表时，判断HASH中的每一条记录进行更新</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#该参数已经被标注为过期参数</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#slave-rows-search-algorithms = &#39;INDEX_SCAN,HASH_SCAN&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># default value is CRC32</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#binlog_checksum = 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># default value is ON</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#relay-log-purge = 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- Bin-Log设置 结束 --##########################################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- 可能用到的MyISAM性能设置 开始 --#############################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#对MyISAM表起作用，但是内部的临时磁盘表是MyISAM表，也要使用该值。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#可以使用检查状态值 created_tmp_disk_tables 得知详情</span></span>
<span class="line"><span style="color:#F07178;">key_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 15M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#对MyISAM表起作用，但是内部的临时磁盘表是MyISAM表，也要使用该值，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#例如大表order by、缓存嵌套查询、大容量插入分区。</span></span>
<span class="line"><span style="color:#F07178;">read_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#对MyISAM表起作用 读取优化</span></span>
<span class="line"><span style="color:#F07178;">read_rnd_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#对MyISAM表起作用 插入优化</span></span>
<span class="line"><span style="color:#F07178;">bulk_insert_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 64M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- 可能用到的MyISAM性能设置 开始 --################################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- innodb性能设置 开始 --##########################################</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># Defines the maximum number of threads permitted inside of InnoDB. </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># A value of 0 (the default) is interpreted as infinite concurrency (no limit)</span></span>
<span class="line"><span style="color:#F07178;">innodb_thread_concurrency</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#一般设置物理存储的 60% ~ 70%</span></span>
<span class="line"><span style="color:#F07178;">innodb_buffer_pool_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8G</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#当缓冲池大小大于1GB时，将innodb_buffer_pool_instances设置为大于1的值，可以提高繁忙服务器的可伸缩性</span></span>
<span class="line"><span style="color:#F07178;">innodb_buffer_pool_instances</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#默认启用。指定在MySQL服务器启动时，InnoDB缓冲池通过加载之前保存的相同页面自动预热。 通常与innodb_buffer_pool_dump_at_shutdown结合使用</span></span>
<span class="line"><span style="color:#F07178;">innodb_buffer_pool_load_at_startup</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#默认启用。指定在MySQL服务器关闭时是否记录在InnoDB缓冲池中缓存的页面，以便在下次重新启动时缩短预热过程</span></span>
<span class="line"><span style="color:#F07178;">innodb_buffer_pool_dump_at_shutdown</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># Defines the name, size, and attributes of InnoDB system tablespace data files</span></span>
<span class="line"><span style="color:#F07178;">innodb_data_file_path</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> ibdata1:1G:autoextend</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#InnoDB用于写入磁盘日志文件的缓冲区大小（以字节为单位）。默认值为16MB</span></span>
<span class="line"><span style="color:#F07178;">innodb_log_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 32M</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#InnoDB日志文件组数量</span></span>
<span class="line"><span style="color:#F07178;">innodb_log_files_in_group</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 3</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#InnoDB日志文件组中每一个文件的大小</span></span>
<span class="line"><span style="color:#F07178;">innodb_log_file_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 2G</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#是否开启在线回收（收缩）undo log日志文件，支持动态设置，默认开启</span></span>
<span class="line"><span style="color:#F07178;">innodb_undo_log_truncate</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#当超过这个阀值（默认是1G），会触发truncate回收（收缩）动作，truncate后空间缩小到10M</span></span>
<span class="line"><span style="color:#F07178;">innodb_max_undo_log_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4G</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#The path where InnoDB creates undo tablespaces</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#没有配置则在数据文件目录下</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#innodb_undo_directory = /var/lib/mysql/undolog</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#用于设定创建的undo表空间的个数</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#已经弃用了，只能手动添加undo表空间</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#The innodb_undo_tablespaces variable is deprecated and is no longer configurable as of MySQL 8.0.14</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#innodb_undo_tablespaces = 95</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#提高刷新脏页数量和合并插入数量，改善磁盘I/O处理能力</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#根据您的服务器IOPS能力适当调整</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#一般配普通SSD盘的话，可以调整到 10000 - 20000</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#配置高端PCIe SSD卡的话，则可以调整的更高，比如 50000 - 80000</span></span>
<span class="line"><span style="color:#F07178;">innodb_io_capacity</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4000</span></span>
<span class="line"><span style="color:#F07178;">innodb_io_capacity_max</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8000</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#如果打开参数innodb_flush_sync, checkpoint时，flush操作将由page cleaner线程来完成，此时page cleaner会忽略io capacity的限制，进入激烈刷脏</span></span>
<span class="line"><span style="color:#F07178;">innodb_flush_sync</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0</span></span>
<span class="line"><span style="color:#F07178;">innodb_flush_neighbors</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#CPU多核处理能力设置，假设CPU是4颗8核的，设置如下</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#读多，写少可以设成 2:6的比例</span></span>
<span class="line"><span style="color:#F07178;">innodb_write_io_threads</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8</span></span>
<span class="line"><span style="color:#F07178;">innodb_read_io_threads</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8</span></span>
<span class="line"><span style="color:#F07178;">innodb_purge_threads</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4</span></span>
<span class="line"><span style="color:#F07178;">innodb_page_cleaners</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4</span></span>
<span class="line"><span style="color:#F07178;">innodb_open_files</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 65535</span></span>
<span class="line"><span style="color:#F07178;">innodb_max_dirty_pages_pct</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 50</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#该参数针对unix、linux，window上直接注释该参数.默认值为 NULL</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#O_DIRECT减少操作系统级别VFS的缓存和Innodb本身的buffer缓存之间的冲突</span></span>
<span class="line"><span style="color:#F07178;">innodb_flush_method</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> O_DIRECT</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">innodb_lru_scan_depth</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4000</span></span>
<span class="line"><span style="color:#F07178;">innodb_checksum_algorithm</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> crc32</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#为了获取被锁定的资源最大等待时间，默认50秒，超过该时间会报如下错误:</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction</span></span>
<span class="line"><span style="color:#F07178;">innodb_lock_wait_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 20</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#默认OFF，如果事务因为加锁超时，会回滚上一条语句执行的操作。如果设置ON，则整个事务都会回滚</span></span>
<span class="line"><span style="color:#F07178;">innodb_rollback_on_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#强所有发生的死锁错误信息记录到 error.log中，之前通过命令行只能查看最近一次死锁信息</span></span>
<span class="line"><span style="color:#F07178;">innodb_print_all_deadlocks</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#在创建InnoDB索引时用于指定对数据排序的排序缓冲区的大小</span></span>
<span class="line"><span style="color:#F07178;">innodb_sort_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 67108864</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#控制着在向有auto_increment 列的表插入数据时，相关锁的行为，默认为2</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#0：traditonal （每次都会产生表锁）</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#1：consecutive （mysql的默认模式，会产生一个轻量锁，simple insert会获得批量的锁，保证连续插入）</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#2：interleaved （不会锁表，来一个处理一个，并发最高）</span></span>
<span class="line"><span style="color:#F07178;">innodb_autoinc_lock_mode</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#表示每个表都有自已独立的表空间</span></span>
<span class="line"><span style="color:#F07178;">innodb_file_per_table</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#指定Online DDL执行期间产生临时日志文件的最大大小，单位字节，默认大小为128MB。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#日志文件记录的是表在DDL期间的数据插入、更新和删除信息(DML操作)，一旦日志文件超过该参数指定值时，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#DDL执行就会失败并回滚所有未提交的当前DML操作，所以，当执行DDL期间有大量DML操作时可以提高该参数值，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#但同时也会增加DDL执行完成时应用日志时锁定表的时间</span></span>
<span class="line"><span style="color:#F07178;">innodb_online_alter_log_max_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4G</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#--###########################-- innodb性能设置 结束 --##########################################</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">[mysqldump]</span></span>
<span class="line"><span style="color:#A6ACCD;">quick</span></span>
<span class="line"><span style="color:#F07178;">max_allowed_packet</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 128M</span></span></code></pre></div><h2 id="配置优化备选" tabindex="-1">配置优化备选 <a class="header-anchor" href="#配置优化备选" aria-label="Permalink to &quot;配置优化备选&quot;">​</a></h2><div class="language-properties"><button title="Copy Code" class="copy"></button><span class="lang">properties</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[client]</span></span>
<span class="line"><span style="color:#F07178;">port</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 3306</span></span>
<span class="line"><span style="color:#F07178;">socket</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /tmp/mysql.sock</span></span>
<span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#F07178;">port</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 3306</span></span>
<span class="line"><span style="color:#F07178;">socket</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /tmp/mysql.sock</span></span>
<span class="line"><span style="color:#F07178;">basedir</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /usr/local/mysql</span></span>
<span class="line"><span style="color:#F07178;">datadir</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /data/mysql</span></span>
<span class="line"><span style="color:#F07178;">pid-file</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /data/mysql/mysql.pid</span></span>
<span class="line"><span style="color:#F07178;">user</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> mysql</span></span>
<span class="line"><span style="color:#F07178;">bind-address</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0.0.0.0</span></span>
<span class="line"><span style="color:#F07178;">server-id</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1 </span><span style="color:#676E95;font-style:italic;">#表示是本机的序号为1,一般来讲就是master的意思</span></span>
<span class="line"><span style="color:#A6ACCD;">skip-name-resolve</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 禁止MySQL对外部连接进行DNS解析，使用这一选项可以消除MySQL进行DNS解析的时间。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 但需要注意，如果开启该选项，则所有远程主机连接授权都要使用IP地址方式，否则MySQL将无法正常处理连接请求</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#skip-networking</span></span>
<span class="line"><span style="color:#F07178;">back_log</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 600</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL能有的连接数量。当主要MySQL线程在一个很短时间内得到非常多的连接请求，这就起作用，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 然后主线程花些时间(尽管很短)检查连接并且启动一个新线程。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># back_log值指出在MySQL暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果期望在一个短时间内有很多连接，你需要增加它。也就是说，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果MySQL的连接数据达到max_connections时，新来的请求将会被存在堆栈中，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 以等待某一连接释放资源，该堆栈的数量即back_log，如果等待连接的数量超过back_log，将不被授予连接资源。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 另外，这值（back_log）限于您的操作系统对到来的TCP/IP连接的侦听队列的大小。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 你的操作系统在这个队列大小上有它自己的限制（可以检查你的OS文档找出这个变量的最大值），</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 试图设定back_log高于你的操作系统的限制将是无效的。</span></span>
<span class="line"><span style="color:#F07178;">max_connections</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1000</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL的最大连接数，如果服务器的并发连接请求量比较大，建议调高此值，以增加并行连接数量，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 当然这建立在机器能支撑的情况下，因为如果连接数越多，介于MySQL会为每个连接提供连接缓冲区，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 就会开销越多的内存，所以要适当调整该值，不能盲目提高设值。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 可以过&#39;conn%&#39;通配符查看当前状态的连接数量，以定夺该值的大小。</span></span>
<span class="line"><span style="color:#F07178;">max_connect_errors</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 6000</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 对于同一主机，如果有超出该参数值个数的中断错误连接，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 则该主机将被禁止连接。如需对该主机进行解禁，执行：FLUSH HOST。</span></span>
<span class="line"><span style="color:#F07178;">open_files_limit</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 65535</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL打开的文件描述符限制，默认最小1024;当open_files_limit没有被配置的时候，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 比较max_connections*5和ulimit -n的值，哪个大用哪个，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 当open_file_limit被配置的时候，比较open_files_limit和max_connections*5的值，哪个大用哪个</span></span>
<span class="line"><span style="color:#F07178;">table_open_cache</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 128</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL每打开一个表，都会读入一些数据到table_open_cache缓存中，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 当MySQL在这个缓存中找不到相应信息时，才会去磁盘上读取。默认值64</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 假定系统有200个并发连接，则需将此参数设置为200*N(N为每个连接所需的文件描述符数目)；</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 当把table_open_cache设置为很大时，如果系统处理不了那么多文件描述符，那么就会出现客户端失效，连接不上</span></span>
<span class="line"><span style="color:#F07178;">max_allowed_packet</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 接受的数据包大小；增加该变量的值十分安全，这是因为仅当需要时才会分配额外内存。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 例如，仅当你发出长查询或MySQLd必须返回大的结果行时MySQLd才会分配更多内存。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 该变量之所以取较小默认值是一种预防措施，以捕获客户端和服务器之间的错误信息包，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 并确保不会因偶然使用大的信息包而导致内存溢出。</span></span>
<span class="line"><span style="color:#F07178;">binlog_cache_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 一个事务，在没有提交的时候，产生的日志，记录到Cache中；</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 等到事务提交需要提交的时候，则把日志持久化到磁盘。默认binlog_cache_size大小32K</span></span>
<span class="line"><span style="color:#F07178;">max_heap_table_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 定义了用户可以创建的内存表(memory table)的大小。这个值用来计算内存表的最大行数值。这个变量支持动态改变</span></span>
<span class="line"><span style="color:#F07178;">tmp_table_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 16M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL的heap（堆积）表缓冲大小。所有联合在一个DML指令内完成，并且大多数联合甚至可以不用临时表即可以完成</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 大多数临时表是基于内存的(HEAP)表。具有大的记录长度的临时表 (所有列的长度的和)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 或包含BLOB列的表存储在硬盘上。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果某个内部heap（堆积）表大小超过tmp_table_size，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL可以根据需要自动将内存中的heap表改为基于硬盘的MyISAM表。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 还可以通过设置tmp_table_size选项来增加临时表的大小。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 也就是说，如果调高该值，MySQL同时将增加heap表的大小，可达到提高联接查询速度的效果</span></span>
<span class="line"><span style="color:#F07178;">read_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 2M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL读入缓冲区大小。对表进行顺序扫描的请求将分配一个读入缓冲区，MySQL会为它分配一段内存缓冲区read_buffer_size变量控制这一缓冲区的大小。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果对表的顺序扫描请求非常频繁，并且你认为频繁扫描进行得太慢，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 可以通过增加该变量值以及内存缓冲区大小提高其性能</span></span>
<span class="line"><span style="color:#F07178;">read_rnd_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL的随机读缓冲区大小。当按任意顺序读取行时(例如，按照排序顺序)，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 将分配一个随机读缓存区。进行排序查询时，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL会首先扫描一遍该缓冲，以避免磁盘搜索，提高查询速度，如果需要排序大量数据，可适当调高该值。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 但MySQL会为每个客户连接发放该缓冲空间，所以应尽量适当设置该值，以避免内存开销过大</span></span>
<span class="line"><span style="color:#F07178;">sort_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL执行排序使用的缓冲大小。如果想要增加ORDER BY的速度，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 首先看是否可以让MySQL使用索引而不是额外的排序阶段。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果不能，可以尝试增加sort_buffer_size变量的大小</span></span>
<span class="line"><span style="color:#F07178;">join_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 联合查询操作所能使用的缓冲区大小，和sort_buffer_size一样，该参数对应的分配内存也是每连接独享</span></span>
<span class="line"><span style="color:#F07178;">thread_cache_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 这个值（默认8）表示可以重新利用保存在缓存中线程的数量，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 当断开连接时如果缓存中还有空间，那么客户端的线程将被放到缓存中，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果线程重新被请求，那么请求将从缓存中读取,如果缓存中是空的或者是新的请求，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 那么这个线程将被重新创建,如果有很多新的线程，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 增加这个值可以改善系统性能.通过比较Connections和Threads_created状态的变量，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 可以看到这个变量的作用。(–&gt;表示要调整的值)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 根据物理内存设置规则如下：</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 1G  —&gt; 8</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 2G  —&gt; 16</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 3G  —&gt; 32</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 大于3G  —&gt; 64</span></span>
<span class="line"><span style="color:#F07178;">query_cache_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#MySQL的查询缓冲大小（从4.0.1开始，MySQL提供了查询缓冲机制）使用查询缓冲，MySQL将SELECT语句和查询结果存放在缓冲区中，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 今后对于同样的SELECT语句（区分大小写），将直接从缓冲区中读取结果。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 根据MySQL用户手册，使用查询缓冲最多可以达到238%的效率。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 通过检查状态值&#39;Qcache_%&#39;，可以知道query_cache_size设置是否合理：</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果Qcache_lowmem_prunes的值非常大，则表明经常出现缓冲不够的情况，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果Qcache_hits的值也非常大，则表明查询缓冲使用非常频繁，此时需要增加缓冲大小；</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果Qcache_hits的值不大，则表明你的查询重复率很低，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 这种情况下使用查询缓冲反而会影响效率，那么可以考虑不用查询缓冲。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 此外，在SELECT语句中加入SQL_NO_CACHE可以明确表示不使用查询缓冲</span></span>
<span class="line"><span style="color:#F07178;">query_cache_limit</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 2M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 指定单个查询能够使用的缓冲区大小，默认1M</span></span>
<span class="line"><span style="color:#F07178;">key_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 指定用于索引的缓冲区大小，增加它可得到更好处理的索引(对所有读和多重写)，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 到你能负担得起那样多。如果你使它太大，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 系统将开始换页并且真的变慢了。对于内存在4GB左右的服务器该参数可设置为384M或512M。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 通过检查状态值Key_read_requests和Key_reads，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 可以知道key_buffer_size设置是否合理。比例key_reads/key_read_requests应该尽可能的低，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 至少是1:100，1:1000更好(上述状态值可以使用SHOW STATUS LIKE &#39;key_read%&#39;获得)。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注意：该参数值设置的过大反而会是服务器整体效率降低</span></span>
<span class="line"><span style="color:#F07178;">ft_min_word_len</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 分词词汇最小长度，默认4</span></span>
<span class="line"><span style="color:#F07178;">transaction_isolation</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> REPEATABLE-READ</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL支持4种事务隔离级别，他们分别是：</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE.</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如没有指定，MySQL默认采用的是REPEATABLE-READ，ORACLE默认的是READ-COMMITTED</span></span>
<span class="line"><span style="color:#F07178;">log_bin</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> mysql-bin</span></span>
<span class="line"><span style="color:#F07178;">binlog_format</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> mixed</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 超过30天的binlog删除</span></span>
<span class="line"><span style="color:#F07178;">expire_logs_days</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 30</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 错误日志路径</span></span>
<span class="line"><span style="color:#F07178;">log_error</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /data/mysql/mysql-error.log </span></span>
<span class="line"><span style="color:#F07178;">slow_query_log</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"><span style="color:#F07178;">long_query_time</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1 </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 慢查询时间 超过1秒则为慢查询</span></span>
<span class="line"><span style="color:#F07178;">slow_query_log_file</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /data/mysql/mysql-slow.log</span></span>
<span class="line"><span style="color:#F07178;">performance_schema</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0</span></span>
<span class="line"><span style="color:#A6ACCD;">explicit_defaults_for_timestamp</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#lower_case_table_names = 1 #不区分大小写</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL选项以避免外部锁定。该选项默认开启</span></span>
<span class="line"><span style="color:#A6ACCD;">skip-external-locking </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 默认存储引擎</span></span>
<span class="line"><span style="color:#F07178;">default-storage-engine</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> InnoDB </span></span>
<span class="line"><span style="color:#F07178;">innodb_file_per_table</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># InnoDB为独立表空间模式，每个数据库的每个表都会生成一个数据空间</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 独立表空间优点：</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 1．每个表都有自已独立的表空间。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 2．每个表的数据和索引都会存在自已的表空间中。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 3．可以实现单表在不同的数据库中移动。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 4．空间可以回收（除drop table操作处，表空不能自已回收）</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 缺点：单表增加过大，如超过100G</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 结论：共享表空间在Insert操作上少有优势。其它都没独立表空间表现好。当启用独立表空间时，请合理调整：innodb_open_files</span></span>
<span class="line"><span style="color:#F07178;">innodb_open_files</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 500</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 限制Innodb能打开的表的数据，如果库里的表特别多的情况，请增加这个。这个值默认是300</span></span>
<span class="line"><span style="color:#F07178;">innodb_buffer_pool_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 64M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># InnoDB使用一个缓冲池来保存索引和原始数据, 不像MyISAM.</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 这里你设置越大,你在存取表里面数据时所需要的磁盘I/O越少.</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 在一个独立使用的数据库服务器上,你可以设置这个变量到服务器物理内存大小的80%</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 不要设置过大,否则,由于物理内存的竞争可能导致操作系统的换页颠簸.</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注意在32位系统上你每个进程可能被限制在 2-3.5G 用户层面内存限制,所以不要设置的太高.</span></span>
<span class="line"><span style="color:#F07178;">innodb_write_io_threads</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4</span></span>
<span class="line"><span style="color:#F07178;">innodb_read_io_threads</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># innodb使用后台线程处理数据页上的读写 I/O(输入输出)请求,根据你的 CPU 核数来更改,默认是4</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 注:这两个参数不支持动态改变,需要把该参数加入到my.cnf里，修改完后重启MySQL服务,允许值的范围从 1-64</span></span>
<span class="line"><span style="color:#F07178;">innodb_thread_concurrency</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 0</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 默认设置为 0,表示不限制并发数，这里推荐设置为0，更好去发挥CPU多核处理能力，提高并发量</span></span>
<span class="line"><span style="color:#F07178;">innodb_purge_threads</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># InnoDB中的清除操作是一类定期回收无用数据的操作。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 在之前的几个版本中，清除操作是主线程的一部分，这意味着运行时它可能会堵塞其它的数据库操作。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 从MySQL5.5.X版本开始，该操作运行于独立的线程中,并支持更多的并发数。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 用户可通过设置innodb_purge_threads配置参数来选择清除操作是否使用单</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 独线程,默认情况下参数设置为0(不使用单独线程),设置为 1 时表示使用单独的清除线程。建议为1</span></span>
<span class="line"><span style="color:#F07178;">innodb_flush_log_at_trx_commit</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 2</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 0：如果innodb_flush_log_at_trx_commit的值为0,log buffer每秒就会被刷写日志文件到磁盘，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 提交事务的时候不做任何操作（执行是由mysql的master thread线程来执行的。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 主线程中每秒会将重做日志缓冲写入磁盘的重做日志文件(REDO LOG)中。不论事务是否已经提交）</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 默认的日志文件是ib_logfile0,ib_logfile1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 1：当设为默认值1的时候，每次提交事务的时候，都会将log buffer刷写到日志。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 2：如果设为2,每次提交事务都会写日志，但并不会执行刷的操作。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 每秒定时会刷到日志文件。要注意的是，并不能保证100%每秒一定都会刷到磁盘，这要取决于进程的调度。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 每次事务提交的时候将数据写入事务日志，而这里的写入仅是调用了文件系统的写入操作，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 而文件系统是有 缓存的，所以这个写入并不能保证数据已经写入到物理磁盘</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 默认值1是为了保证完整的ACID。当然，你可以将这个配置项设为1以外的值来换取更高的性能，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 但是在系统崩溃的时候，你将会丢失1秒的数据。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设为0的话，mysqld进程崩溃的时候，就会丢失最后1秒的事务。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设为2,只有在操作系统崩溃或者断电的时候才会丢失最后1秒的数据。InnoDB在做恢复的时候会忽略这个值。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 总结</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设为1当然是最安全的，但性能页是最差的（相对其他两个参数而言，但不是不能接受）。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果对数据一致性和完整性要求不高，完全可以设为2，如果只最求性能，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 例如高并发写的日志服务器，设为0来获得更高性能</span></span>
<span class="line"><span style="color:#F07178;">innodb_log_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 2M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 此参数确定些日志文件所用的内存大小，以M为单位。缓冲区更大能提高性能，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 但意外的故障将会丢失数据。MySQL开发人员建议设置为1－8M之间</span></span>
<span class="line"><span style="color:#F07178;">innodb_log_file_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 32M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 此参数确定数据日志文件的大小，更大的设置可以提高性能，但也会增加恢复故障数据库所需的时间</span></span>
<span class="line"><span style="color:#F07178;">innodb_log_files_in_group</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 3</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 为提高性能，MySQL可以以循环方式将日志文件写到多个文件。推荐设置为3</span></span>
<span class="line"><span style="color:#F07178;">innodb_max_dirty_pages_pct</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 90</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># innodb主线程刷新缓存池中的数据，使脏数据比例小于90%</span></span>
<span class="line"><span style="color:#F07178;">innodb_lock_wait_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 120 </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># InnoDB事务在被回滚之前可以等待一个锁定的超时秒数</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># InnoDB在它自己的锁定表中自动检测事务死锁并且回滚事务</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># InnoDB用LOCK TABLES语句注意到锁定设置。默认值是50秒</span></span>
<span class="line"><span style="color:#F07178;">bulk_insert_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 批量插入缓存大小， 这个参数是针对MyISAM存储引擎来说的。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 适用于在一次性插入100-1000+条记录时， 提高效率。默认值是8M。可以针对数据量的大小，翻倍增加。</span></span>
<span class="line"><span style="color:#F07178;">myisam_sort_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MyISAM设置恢复表之时使用的缓冲区的尺寸，当在REPAIR TABLE或用CREATE INDEX创建索引</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 或ALTER TABLE过程中排序 MyISAM索引分配的缓冲区</span></span>
<span class="line"><span style="color:#F07178;">myisam_max_sort_file_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 10G</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果临时文件会变得超过索引，不要使用快速排序索引方法来创建一个索引。注释：这个参数以字节的形式给出</span></span>
<span class="line"><span style="color:#F07178;">myisam_repair_threads</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果该值大于1，在Repair by sorting过程中并行创建MyISAM表索引(每个索引在自己的线程内) </span></span>
<span class="line"><span style="color:#F07178;">interactive_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 28800</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 服务器关闭交互式连接前等待活动的秒数。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 默认值：28800秒（8小时）</span></span>
<span class="line"><span style="color:#F07178;">wait_timeout</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 28800</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 服务器关闭非交互连接之前等待活动的秒数。在线程启动时，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 根据全局wait_timeout值或全局interactive_timeout值初始化会话wait_timeout值，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 取决于客户端类型(由mysql_real_connect()的连接选项CLIENT_INTERACTIVE定义)。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 参数默认值：28800秒（8小时）</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># MySQL服务器所支持的最大连接数是有上限的，因为每个连接的建立都会消耗内存，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 因此我们希望客户端在连接到MySQL Server处理完相应的操作后，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 应该断开连接并释放占用的内存。如果你的MySQL Server有大量的闲置连接，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 他们不仅会白白消耗内存，而且如果连接一直在累加而不断开，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 最终肯定会达到MySQL Server的连接上限数，这会报&#39;too many connections&#39;的错误。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 对于wait_timeout的值设定，应该根据系统的运行情况来判断。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 在系统运行一段时间后，可以通过show processlist命令查看当前系统的连接状态，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如果发现有大量的sleep状态的连接进程，则说明该参数设置的过大，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 可以进行适当的调整小些。要同时设置interactive_timeout和wait_timeout才会生效。</span></span>
<span class="line"><span style="color:#89DDFF;">[mysqldump]</span></span>
<span class="line"><span style="color:#A6ACCD;">quick</span></span>
<span class="line"><span style="color:#F07178;">max_allowed_packet</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 16M </span><span style="color:#676E95;font-style:italic;">#服务器发送和接受的最大包长度</span></span>
<span class="line"><span style="color:#89DDFF;">[myisamchk]</span></span>
<span class="line"><span style="color:#F07178;">key_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#F07178;">sort_buffer_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 8M</span></span>
<span class="line"><span style="color:#F07178;">read_buffer</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span>
<span class="line"><span style="color:#F07178;">write_buffer</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4M</span></span></code></pre></div><h1 id="数据恢复" tabindex="-1">数据恢复 <a class="header-anchor" href="#数据恢复" aria-label="Permalink to &quot;数据恢复&quot;">​</a></h1><blockquote><p>一般来说，在生产环境DBA都会在定期生成全量数据的备份，然后开启binlog记录增量数据。恢复的时候借助数据备份和binlog日志一般情况下是可以很大程度上复原数据，当然一般情况下开发也不会拥有删库的权限，一般都是有删除数据的权限。所以我们在遇到这种紧急情况不能慌，要赶紧去想办法补救。<a href="https://mp.weixin.qq.com/s?__biz=MzI1NzI5NDM4Mw==&amp;mid=2247495274&amp;idx=1&amp;sn=994800c3833570311fbb56fd3fefe26c&amp;chksm=ea1b072add6c8e3cf0c833733e33794b15ef71505ffed4e56721642cc9b8414688ee111ca162&amp;mpshare=1&amp;scene=23&amp;srcid=06092XEdcYSAZqsxhWsOtsrV&amp;sharer_sharetime=1686270792091&amp;sharer_shareid=29b8a04db1dbd975e3bf4e9f47e7ac67#rd" target="_blank" rel="noreferrer">删库不再跑路！我在里面含泪写下 MySQL 数据恢复大法（重要，还没搞）</a></p></blockquote><blockquote><p>最简单，也是最实用的方式就是在我们接到，清理数据，或者是修改数据的需求时，先将<strong>数据备份</strong>，备份是王道。这样会让我们的数据恢复变得更容易。一般在企业中，DBA都会有备份脚本，他们会长期定时对数据进行备份，防止发生悲剧。</p></blockquote><h2 id="规范操作" tabindex="-1">规范操作 <a class="header-anchor" href="#规范操作" aria-label="Permalink to &quot;规范操作&quot;">​</a></h2><p>操作前，先备份，不要怕麻烦，出错后就悔不当初了；</p><p>删除数据库、表时，不要直接用drop命令，而是重命名到一个专用归档库里；</p><p>删除数据时，不要直接用delete或truncate命令，尤其是truncate命令，目前不支持事务，无法回滚；</p><p>使用delete命令删除数据时，应当先开启事务，这样误操作时，还是有机会进行回滚；</p><p>要大批量删除数据时，可以将这些数据插入到一个新表中，确认无误后再删除。或者把要保留的数据写到新表，然后将表重命名对掉，这样需要注意的是增量数据，不要把新插入的数据丢掉；</p><h2 id="基本的恢复流程" tabindex="-1">基本的恢复流程 <a class="header-anchor" href="#基本的恢复流程" aria-label="Permalink to &quot;基本的恢复流程&quot;">​</a></h2><ul><li>看看是否有定期备份，和binlog日志（没有就凉凉）</li><li>先备份数据恢复</li><li>用mysqlbinlog命令将上述的binlog文件导出为sql文件，并剔除其中的drop语句</li><li>恢复binlog中增量数据的部分</li></ul><h2 id="补救措施" tabindex="-1">补救措施 <a class="header-anchor" href="#补救措施" aria-label="Permalink to &quot;补救措施&quot;">​</a></h2><ol><li>优先考虑是否能只通过binlog恢复，不能的化，再考虑其它</li><li>执行 DROP DATABASE / DROP TABLE 命令误删库表时，如果采用的是共享表空间模式，还有恢复的机会。如果不是，直接从备份文件恢复吧；在共享表空间模式下，误删后立刻杀掉（kill -9）mysql相关进程（mysqld_safe、mysqld），然后尝试从ibdataX文件中恢复数据；</li><li>误删除正在运行中的MySQL表ibd或ibdataX文件。利用linux系统的proc文件特点，把该ibd文件从内存中拷出来，再进行恢复，因为此时mysqld实例在内存中是保持打开该文件的，切记这时不要把mysqld实例关闭了。此模式恢复，需要停止线上业务对该实例的写入操作，不再写入新数据，防止丢失新数据。把复制出来的ibd 或 ibdataX文件拷贝回datadir后，重启mysqld进入recovery模式，innodb_force_recovery 选项从 0 - 6 逐级测试，直至能备份出整个实例或单表的所有数据后，再重建实例或单表，恢复数据。</li><li>未开启事务模式下，执行delete误删数据。发现问题严重性后，立即将mysqld（以及mysqld_safe）进程杀掉（kill -9），然后再用工具将表空间数据读取出来。因为执行delete删除后，实际数据并没有从磁盘清除，只是先打上deleted-mark标签，后续再统一清理，因此快速杀掉进程可以防止数据被物理删除。</li><li>执行truncate误清整张表。如果没使用共享表空间模式的话，直接使用备份恢复和binlog恢复。</li><li>执行不带where条件的update，或者update错数据。数据规模大没法补救的话，也只能通过走备份恢复和binlog恢复。</li></ol><h2 id="相关操作" tabindex="-1">相关操作 <a class="header-anchor" href="#相关操作" aria-label="Permalink to &quot;相关操作&quot;">​</a></h2><p>查看是否开启binlog日志</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> log_bin是ON，就说明打开了 OFF就是关闭状态。</span></span>
<span class="line"><span style="color:#A6ACCD;">show variables like </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">log_bin</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> log_bin相关的内容都能查到</span></span>
<span class="line"><span style="color:#A6ACCD;">show variables like </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%log_bin%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">;</span></span></code></pre></div><p>binlog日志位置</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%datadir%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">;</span></span></code></pre></div><p>根据binlog日志恢复数据</p><ul><li>cd 到binlog文件目录</li><li>mysql安装目录/mysql/bin/下找到binlog日志解析工具mysqlbinlog</li><li>通过mysqlbinlog工具命令按照对应时间解析binlog日志内容，输出到新的文件中</li></ul><p>该工具也支持过滤指定表的相关操作记录</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mysqlbinlog </span><span style="color:#676E95;font-style:italic;">--base64-output=decode-rows -v </span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;font-style:italic;">--database=mall </span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;font-style:italic;">--start-datetime=&quot;2021-09-17 20:50:00&quot; </span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;font-style:italic;">--stop-datetime=&quot;2021-09-17 21:30:00&quot; </span></span>
<span class="line"><span style="color:#A6ACCD;">  D:\tmp\mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bin.000001 </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> mysqllog.sql</span></span></code></pre></div><p>对参数进行一下说明：</p><ul><li><code>base64-output=decode-rows</code>：基于行事件解析成 sql 语句，并将数据转换正常的字符。</li><li><code>database</code>：数据库名。</li><li><code>start-datetime</code>：从 binlog 中第一个等于或晚于该时间戳的事件开始读取，也就是恢复数据的起始时间。</li><li><code>stop-datetime</code>：与上面对应的，是恢复数据的结束时间。</li><li><code>D:\tmp\mysql-bin.000001</code>：恢复数据的日志文件。</li><li><code>mysqllog.sql</code>：恢复数据的输出文件。</li></ul><p>执行完成后，在<code>bin</code>目录下会生成一个<code>mysqllog.sql</code>的文件，打开文件看一下，可以找到删除时执行的<code>delete</code>语句：从语句中可以拿到<code>delete</code>命令执行时每一行数据的值，这样就可以进行数据的恢复了。如果需要恢复的数据量非常大的话，建议使用脚本批量将<code>delete</code>语句转换为<code>insert</code>语句，减轻恢复数据的工作量。</p><p>通过配置文件对binlog 日志进行配置</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 日志格式</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> Statement模式，每一条会修改数据的sql都会记录在binlog中。</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> Row模式，</span><span style="color:#F78C6C;">5.1.5</span><span style="color:#A6ACCD;">版本的MySQL才开始支持row</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">它不记录sql语句上下文相关信息，仅保存哪条记录被修改。</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> Mixed模式，一般的语句修改使用statment格式保存binlog，如一些函数，statement无法完成主从复制的操作，则采用row格式保存binlog，MySQL会根据执行的每一条具体的sql语句来区分对待记录的日志形式，也就是在Statement和Row之间选择一种。</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 设置日志格式</span></span>
<span class="line"><span style="color:#A6ACCD;">binlog_format </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> mixed</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 设置日志路径，需要注意的是该路经需要mysql用户有写权限</span></span>
<span class="line"><span style="color:#A6ACCD;">log</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bin </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">logs</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">log</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 设置binlog清理时间</span></span>
<span class="line"><span style="color:#A6ACCD;">expire_logs_days </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">7</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> binlog每个日志文件大小</span></span>
<span class="line"><span style="color:#A6ACCD;">max_binlog_size </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">100m</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> binlog缓存大小</span></span>
<span class="line"><span style="color:#A6ACCD;">binlog_cache_size </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">4m</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 最大binlog缓存大小</span></span>
<span class="line"><span style="color:#A6ACCD;">max_binlog_cache_size </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">512m</span></span></code></pre></div><h1 id="主从复制⭐" tabindex="-1">主从复制⭐ <a class="header-anchor" href="#主从复制⭐" aria-label="Permalink to &quot;主从复制⭐&quot;">​</a></h1><h2 id="概述" tabindex="-1">概述 <a class="header-anchor" href="#概述" aria-label="Permalink to &quot;概述&quot;">​</a></h2><h3 id="应用场景" tabindex="-1">应用场景 <a class="header-anchor" href="#应用场景" aria-label="Permalink to &quot;应用场景&quot;">​</a></h3><blockquote><p>主从复制是指将主数据库的DDL 和 DML 操作通过二进制日志传到从库服务器中，然后在从库上对这些日志重新执行（也叫重做），从而 使得从库和主库的数据保持同步。</p></blockquote><blockquote><p>MySQL支持一台主库同时向多台从库进行复制，从库同时也可以作为其他从服务器的主库，实现链状复制。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202303021426600.png" alt="image-20230302142651516" style="zoom:80%;"><h3 id="原理" tabindex="-1">原理 <a class="header-anchor" href="#原理" aria-label="Permalink to &quot;原理&quot;">​</a></h3><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202303021429017.png" alt="image-20230302142908937" style="zoom:80%;"><h2 id="搭建主从" tabindex="-1">搭建主从 <a class="header-anchor" href="#搭建主从" aria-label="Permalink to &quot;搭建主从&quot;">​</a></h2><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202303021432762.png" alt="image-20230302143239669" style="zoom:80%;"><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">stop</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">firewalld</span></span>
<span class="line"><span style="color:#FFCB6B;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">disable</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">firewalld</span></span></code></pre></div><h3 id="查看mysql配置文件位置" tabindex="-1">查看MySQL配置文件位置 <a class="header-anchor" href="#查看mysql配置文件位置" aria-label="Permalink to &quot;查看MySQL配置文件位置&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">verbose </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">help </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> grep </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">A </span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Default options</span><span style="color:#89DDFF;">&#39;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261501433.png" alt="image-20220526150106366" style="zoom:80%;"><p>这个信息的意思是： 服务器首先读取的是/etc/my.cnf文件，如果前一个文件不存在则继续读/etc/mysql/my.cnf文件，如若还不存在便会去读~/.my.cnf文件</p><h3 id="主库配置" tabindex="-1">主库配置 <a class="header-anchor" href="#主库配置" aria-label="Permalink to &quot;主库配置&quot;">​</a></h3><blockquote><p>注意：主库中已经创建的数据库不会再进行同步，只有同步开始后新创建的数据库才能同步</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vi </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">my</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cnf</span></span></code></pre></div><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 设置server_id，同一局域网中需要唯一，只有它是必须的，剩下的都是可加可不加的</span></span>
<span class="line"><span style="color:#F07178;">server_id</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">101 </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 是否只读，1代表只读，0代表读写(可选)</span></span>
<span class="line"><span style="color:#F07178;">read-only</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">0</span></span></code></pre></div><p>详细(可选)</p><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 节点ID，确保唯一 一般设置为IP</span></span>
<span class="line"><span style="color:#F07178;">server-id</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1   </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 是否只读，1代表只读，0代表读写(可选)</span></span>
<span class="line"><span style="color:#F07178;">read-only</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">0</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 指定不需要同步的数据库名称</span></span>
<span class="line"><span style="color:#F07178;">binlog-ignore-db</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 复制过滤：需要备份的数据库，输出binlog</span></span>
<span class="line"><span style="color:#F07178;">binlog-do-db</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">book</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 开启mysql的binlog日志功能 可以随便取，最好有含义</span></span>
<span class="line"><span style="color:#F07178;">log-bin</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> mysql-bin  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 控制数据库的binlog刷到磁盘上去 , 0 不控制，性能最好，1每次事物提交都会刷到日志文件中，</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 性能最差，最安全</span></span>
<span class="line"><span style="color:#F07178;">sync_binlog</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#binlog日志格式，mysql默认采用statement，建议使用mixed（mixed,statement,row）</span></span>
<span class="line"><span style="color:#F07178;">binlog_format</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> mixed   </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#binlog过期清理时间 二进制日志自动删除/过期的天数。默认值为0，表示不自动删除</span></span>
<span class="line"><span style="color:#F07178;">expire_logs_days</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 7      </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#binlog每个日志文件大小</span></span>
<span class="line"><span style="color:#F07178;">max_binlog_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 100m     </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#binlog缓存大小  为每个session 分配的内存，在事务过程中用来存储二进制日志的缓存</span></span>
<span class="line"><span style="color:#F07178;">binlog_cache_size</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 4m     </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#最大binlog缓存大</span></span>
<span class="line"><span style="color:#F07178;">max_binlog_cache_size</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> 512m  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#不需要备份的数据库不生成日志文件的数据库，多个忽略数据库可以用逗号拼接，或者 复制这句话，写多行</span></span>
<span class="line"><span style="color:#F07178;">binlog-ignore-db</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql     </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 如：1062错误是指一些主键重复，1032错误是因为主从数据库数据不一致</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 跳过主从复制中遇到的所有错误或指定类型的错误，避免slave端复制中断。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#slave-skip-errors = all #跳过从库错误</span></span>
<span class="line"><span style="color:#F07178;">slave-skip-errors</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> all</span></span></code></pre></div><p>重启MYSQL服务器，如果重启没有报错，证明修改没问题</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl restart mysqld</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl start mysqld</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl stop mysqld</span></span></code></pre></div><p>通过指令,查看二进制日志坐标</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mysql -uroot -p123456</span></span>
<span class="line"><span style="color:#A6ACCD;">show master status ;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220206102052371.png" alt="image-20220206102052371" style="zoom:80%;"><p>字段含义说明：</p><ul><li><p>file : 从哪个日志文件开始推送日志文件</p></li><li><p>position ： 从哪个位置开始推送日志</p></li><li><p>binlog_ignore_db : 指定不需要同步的数据库</p></li></ul><p>登录主库mysql，创建角色和授予权限(可选)，因为主库已经有root用户了，<strong>这个角色不创建也行</strong></p><p>创建用户</p><p>接下来添加一个仅用于数据同步的账户，出于安全考虑，这里仅提供对heima这个库的操作权限。</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">-- 降低密码等级</span></span>
<span class="line"><span style="color:#A6ACCD;">set global validate_password.policy=0;</span></span>
<span class="line"><span style="color:#A6ACCD;">set global validate_password.length=4;</span></span>
<span class="line"><span style="color:#A6ACCD;">-- 创建用户授予权限</span></span>
<span class="line"><span style="color:#A6ACCD;">create user &#39;itcast1&#39;@&#39;%&#39; identified by &#39;itcast&#39;;</span></span>
<span class="line"><span style="color:#A6ACCD;">GRANT  select,replication slave ON *.* TO &#39;itcast1&#39;@&#39;%&#39;;</span></span>
<span class="line"><span style="color:#A6ACCD;">flush privileges;</span></span></code></pre></div><h3 id="从库配置" tabindex="-1">从库配置 <a class="header-anchor" href="#从库配置" aria-label="Permalink to &quot;从库配置&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vi </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">my</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cnf</span></span></code></pre></div><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># mysql服务ID，保证整个集群环境中唯一，取值范围1-2的32次方-1</span></span>
<span class="line"><span style="color:#A6ACCD;">server-id=2</span></span>
<span class="line"><span style="color:#A6ACCD;"># 是否只读，1代表只读，0代表读写(可选)，注意：这表示开发人员对数据库的操作权限</span></span>
<span class="line"><span style="color:#A6ACCD;"># read-only=1</span></span></code></pre></div><p>详细配置(可选)</p><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 设置server_id，同一局域网中需要唯一</span></span>
<span class="line"><span style="color:#F07178;">server_id</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">102</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 指定不需要同步的数据库名称</span></span>
<span class="line"><span style="color:#F07178;">binlog-ignore-db</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 开启二进制日志功能，以备Slave作为其它数据库实例的Master时使用</span></span>
<span class="line"><span style="color:#F07178;">log-bin</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql-slave1-bin</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设置二进制日志使用内存大小（事务）</span></span>
<span class="line"><span style="color:#F07178;">binlog_cache_size</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1M</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设置使用的二进制日志格式（mixed,statement,row）</span></span>
<span class="line"><span style="color:#F07178;">binlog_format</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">row</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 二进制日志过期清理时间。默认值为0，表示不自动清理。</span></span>
<span class="line"><span style="color:#F07178;">expire_logs_days</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">7</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 跳过主从复制中遇到的所有错误或指定类型的错误，避免slave端复制中断。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 如：1062错误是指一些主键重复，1032错误是因为主从数据库数据不一致</span></span>
<span class="line"><span style="color:#F07178;">slave_skip_errors</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1062</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># relay_log配置中继日志</span></span>
<span class="line"><span style="color:#F07178;">relay_log</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mall-mysql-relay-bin</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># log_slave_updates表示slave将复制事件写进自己的二进制日志</span></span>
<span class="line"><span style="color:#F07178;">log_slave_updates</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># slave设置为只读（具有super权限的用户除外）</span></span>
<span class="line"><span style="color:#F07178;">read_only</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1</span></span></code></pre></div><p>重启mysql数据库</p><div class="language-c"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl restart mysqld</span></span></code></pre></div><h3 id="登录从库" tabindex="-1">登录从库 <a class="header-anchor" href="#登录从库" aria-label="Permalink to &quot;登录从库&quot;">​</a></h3><div class="language-c"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">h 192.168.0.155 </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">P </span><span style="color:#F78C6C;">3307</span></span></code></pre></div><p>3、设置和主库关联(根据上面的二进制坐标来填写)</p><blockquote><p>8.0.23之后使用change replication</p></blockquote><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">change replication source to </span></span>
<span class="line"><span style="color:#A6ACCD;">SOURCE_HOST=&#39;192.168.22.145&#39;,</span></span>
<span class="line"><span style="color:#A6ACCD;">SOURCE_USER=&#39;root&#39;,</span></span>
<span class="line"><span style="color:#A6ACCD;">SOURCE_PASSWORD=&#39;123456&#39;,</span></span>
<span class="line"><span style="color:#A6ACCD;">SOURCE_LOG_FILE=&#39;mall-mysql-bin.000002&#39;,</span></span>
<span class="line"><span style="color:#A6ACCD;">SOURCE_LOG_POS=431;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171317671.png" alt="image-20220917131744582" style="zoom:80%;"><blockquote><p>8.0.23之前使用change master</p></blockquote><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">change </span><span style="color:#F78C6C;">master</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">to</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">MASTER_HOST</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">192.168.22.145</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">MASTER_USER</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">root</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">MASTER_PASSWORD</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">MASTER_LOG_FILE</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">mall-mysql-bin.000002</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">MASTER_LOG_POS</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">431</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220206102601205.png" alt="image-20220206102601205" style="zoom:80%;"><p>4、开启同步(从库开启)</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">start replica; # 8.0.22之后，相应的关闭就是stop replica；</span></span>
<span class="line"><span style="color:#A6ACCD;">start slave; # 8.0.22之前</span></span></code></pre></div><p>5、查看同步状态</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show replica status\G;</span></span>
<span class="line"><span style="color:#A6ACCD;">show slave status\G;</span></span></code></pre></div><p>重点看下面这两个，只要都是Yes代表可以了</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220206103238500.png" alt="image-20220206103238500" style="zoom:80%;"><h3 id="测试" tabindex="-1">测试 <a class="header-anchor" href="#测试" aria-label="Permalink to &quot;测试&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mysql -uroot -p -h 192.168.22.145 -P 3306</span></span></code></pre></div><p>在主库创建数据库、表、并插入数据</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">create database ph2;</span></span>
<span class="line"><span style="color:#A6ACCD;">use ph2;</span></span>
<span class="line"><span style="color:#A6ACCD;">create table author (</span></span>
<span class="line"><span style="color:#A6ACCD;">    id int(11) primary key auto_increment,</span></span>
<span class="line"><span style="color:#A6ACCD;">    name varchar(50),</span></span>
<span class="line"><span style="color:#A6ACCD;">    country varchar(50)</span></span>
<span class="line"><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">insert into author values (null,&#39;村上春树&#39;, &#39;日本&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">insert into author values (null,&#39;莫言&#39;, &#39;中国&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">insert into author values (null,&#39;冯唐&#39;, &#39;中国&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">-- 更新</span></span>
<span class="line"><span style="color:#A6ACCD;">update author set name=&#39;刘备&#39; where id=1;</span></span></code></pre></div><p>进入从库进行查询，发现已经主从同步了</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show databases ;</span></span>
<span class="line"><span style="color:#A6ACCD;">use ph2;</span></span>
<span class="line"><span style="color:#A6ACCD;">show tables ;</span></span>
<span class="line"><span style="color:#A6ACCD;">select * from author;</span></span></code></pre></div><h3 id="停止和重置" tabindex="-1">停止和重置 <a class="header-anchor" href="#停止和重置" aria-label="Permalink to &quot;停止和重置&quot;">​</a></h3><p>需要的时候，可以使用如下SQL语句</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">-- 在从机上执行。功能说明：停止I/O 线程和SQL线程的操作。</span></span>
<span class="line"><span style="color:#F78C6C;">stop</span><span style="color:#A6ACCD;"> slave; </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 在从机上执行。功能说明：用于删除SLAVE数据库的relaylog日志文件，并重新启用新的relaylog文件。</span></span>
<span class="line"><span style="color:#F78C6C;">reset</span><span style="color:#A6ACCD;"> slave;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 在主机上执行。功能说明：删除所有的binglog日志文件，并将日志索引文件清空，重新开始所有新的日志文件。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 用于第一次进行搭建主从库时，进行主库binlog初始化工作；</span></span>
<span class="line"><span style="color:#F78C6C;">reset</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">master</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><h3 id="监控连接" tabindex="-1">监控连接 <a class="header-anchor" href="#监控连接" aria-label="Permalink to &quot;监控连接&quot;">​</a></h3><p>主从都可以用它来监控</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show processlist;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171750897.png" alt="image-20220917175059721" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171751630.png" alt="image-20220917175112508" style="zoom:80%;"><h3 id="常见问题" tabindex="-1">常见问题 <a class="header-anchor" href="#常见问题" aria-label="Permalink to &quot;常见问题&quot;">​</a></h3><h4 id="问题1" tabindex="-1">问题1 <a class="header-anchor" href="#问题1" aria-label="Permalink to &quot;问题1&quot;">​</a></h4><p>启动主从同步后，常见错误是<code>Slave_IO_Running： No 或者 Connecting</code> 的情况，此时查看下方的 <code>Last_IO_ERROR</code>错误日志，根据日志中显示的错误信息在网上搜索解决方案即可</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171542809.png" alt="img"></p><p><strong>典型的错误例如：</strong><code>Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: &#39;Client requested master to start replication from position &gt; file size&#39;</code></p><p><strong>解决方案：</strong></p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">-- 在从机停止slave</span></span>
<span class="line"><span style="color:#F78C6C;">stop</span><span style="color:#A6ACCD;"> slave;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 在主机查看mater状态</span></span>
<span class="line"><span style="color:#A6ACCD;">SHOW </span><span style="color:#F78C6C;">MASTER</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">STATUS</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 在主机刷新日志</span></span>
<span class="line"><span style="color:#A6ACCD;">FLUSH LOGS;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 再次在主机查看mater状态（会发现File和Position发生了变化）</span></span>
<span class="line"><span style="color:#A6ACCD;">SHOW </span><span style="color:#F78C6C;">MASTER</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">STATUS</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 修改从机连接主机的SQL，并重新连接即可</span></span></code></pre></div><h4 id="问题2" tabindex="-1">问题2 <a class="header-anchor" href="#问题2" aria-label="Permalink to &quot;问题2&quot;">​</a></h4><p>启动docker容器后提示 <code>WARNING: IPv4 forwarding is disabled. Networking will not work.</code></p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171542811.png" alt="img"></p><p>此错误，虽然不影响主从同步的搭建，但是如果想从远程客户端通过以下方式连接docker中的MySQL则没法连接</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">C:\Users\administrator&gt;mysql</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-h</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">192.168</span><span style="color:#C3E88D;">.100.201</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-P</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3306</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-u</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">root</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span></span></code></pre></div><p><strong>解决方案：</strong></p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">#修改配置文件：</span></span>
<span class="line"><span style="color:#FFCB6B;">vim</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/usr/lib/sysctl.d/00-system.conf</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#追加</span></span>
<span class="line"><span style="color:#FFCB6B;">net.ipv4.ip_forward</span><span style="color:#A6ACCD;">=1</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#接着重启网络</span></span>
<span class="line"><span style="color:#FFCB6B;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">restart</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">network</span></span></code></pre></div><h2 id="docker搭建mysql" tabindex="-1">Docker搭建MySQL <a class="header-anchor" href="#docker搭建mysql" aria-label="Permalink to &quot;Docker搭建MySQL&quot;">​</a></h2><p>创建容器，设置端口映射、目录映射</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3307</span><span style="color:#C3E88D;">:3306</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--privileged=true</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/log1:/var/log/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/data1:/var/lib/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/conf1:/etc/mysql/conf.d</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-e </span><span style="color:#C3E88D;">MYSQL_ROOT_PASSWORD=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;">  \</span></span>
<span class="line"><span style="color:#A6ACCD;">--name </span><span style="color:#C3E88D;">mysql5.7.1</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql:5.7</span></span></code></pre></div><p>创建容器，设置端口映射、目录映射</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3308</span><span style="color:#C3E88D;">:3306</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--privileged=true</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/log2:/var/log/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/data2:/var/lib/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/conf2:/etc/mysql/conf.d</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-e </span><span style="color:#C3E88D;">MYSQL_ROOT_PASSWORD=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;">  \</span></span>
<span class="line"><span style="color:#A6ACCD;">--name </span><span style="color:#C3E88D;">mysql5.7.2</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql:5.7</span></span></code></pre></div><p>创建容器，设置端口映射、目录映射</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3309</span><span style="color:#C3E88D;">:3306</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--privileged=true</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/log3:/var/log/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/data3:/var/lib/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/conf3:/etc/mysql/conf.d</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-e </span><span style="color:#C3E88D;">MYSQL_ROOT_PASSWORD=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;">  \</span></span>
<span class="line"><span style="color:#A6ACCD;">--name </span><span style="color:#C3E88D;">mysql5.7.3</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql:5.7</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171617650.png" alt="image-20220917161748373" style="zoom:80%;"><h3 id="配置文件-1" tabindex="-1">配置文件 <a class="header-anchor" href="#配置文件-1" aria-label="Permalink to &quot;配置文件&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cd /DockerData/mysql/conf1</span></span>
<span class="line"><span style="color:#A6ACCD;">vim my.cnf</span></span></code></pre></div><p>编辑my.cnf</p><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[client]</span></span>
<span class="line"><span style="color:#F07178;">default_character_set</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">utf8</span></span>
<span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#F07178;">collation_server</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> utf8_general_ci</span></span>
<span class="line"><span style="color:#F07178;">character_set_server</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> utf8</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cp my</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cnf </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf2</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">my</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cnf </span></span>
<span class="line"><span style="color:#A6ACCD;">cp my</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cnf </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf3</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">my</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cnf</span></span></code></pre></div><p>重启mysql5.7服务</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker restart mysql5</span><span style="color:#F78C6C;">.7.1</span></span>
<span class="line"><span style="color:#A6ACCD;">docker restart mysql5</span><span style="color:#F78C6C;">.7.2</span></span>
<span class="line"><span style="color:#A6ACCD;">docker restart mysql5</span><span style="color:#F78C6C;">.7.3</span></span></code></pre></div><p>查看编码(修改成功)</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 进入容器，操作mysql</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it mysql5</span><span style="color:#F78C6C;">.7.1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456</span></span></code></pre></div><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like &#39;character%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208130605973.png" alt="image-20220208130605973" style="zoom:67%;"><h3 id="主从配置" tabindex="-1">主从配置 <a class="header-anchor" href="#主从配置" aria-label="Permalink to &quot;主从配置&quot;">​</a></h3><p>主数据库</p><div class="language-properties"><button title="Copy Code" class="copy"></button><span class="lang">properties</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置server_id，同一局域网中需要唯一</span></span>
<span class="line"><span style="color:#F07178;">server_id</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">101 </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 指定不需要同步的数据库名称</span></span>
<span class="line"><span style="color:#F07178;">binlog-ignore-db</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 开启二进制日志功能</span></span>
<span class="line"><span style="color:#F07178;">log-bin</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mall-mysql-bin  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置二进制日志使用内存大小（事务）</span></span>
<span class="line"><span style="color:#F07178;">binlog_cache_size</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1M  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置使用的二进制日志格式（mixed,statement,row）</span></span>
<span class="line"><span style="color:#F07178;">binlog_format</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">row  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 二进制日志过期清理时间。默认值为0，表示不自动清理。</span></span>
<span class="line"><span style="color:#F07178;">expire_logs_days</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">7  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 跳过主从复制中遇到的所有错误或指定类型的错误，避免slave端复制中断。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 如：1062错误是指一些主键重复，1032错误是因为主从数据库数据不一致</span></span>
<span class="line"><span style="color:#F07178;">slave_skip_errors</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1062</span></span></code></pre></div><p>从数据库</p><div class="language-properties"><button title="Copy Code" class="copy"></button><span class="lang">properties</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置server_id，同一局域网中需要唯一</span></span>
<span class="line"><span style="color:#F07178;">server_id</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">102</span></span></code></pre></div><div class="language-properties"><button title="Copy Code" class="copy"></button><span class="lang">properties</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置server_id，同一局域网中需要唯一</span></span>
<span class="line"><span style="color:#F07178;">server_id</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">103</span></span></code></pre></div><h2 id="主从连接配置" tabindex="-1">主从连接配置 <a class="header-anchor" href="#主从连接配置" aria-label="Permalink to &quot;主从连接配置&quot;">​</a></h2><h3 id="主数据库" tabindex="-1">主数据库 <a class="header-anchor" href="#主数据库" aria-label="Permalink to &quot;主数据库&quot;">​</a></h3><p>进入主节点，查看binlog位置</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it mysql5</span><span style="color:#F78C6C;">.7.1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456</span></span>
<span class="line"><span style="color:#A6ACCD;">show master status </span><span style="color:#89DDFF;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171709277.png" alt="image-20220917170939185" style="zoom:80%;"><h3 id="从数据库" tabindex="-1">从数据库 <a class="header-anchor" href="#从数据库" aria-label="Permalink to &quot;从数据库&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it mysql5</span><span style="color:#F78C6C;">.7.2</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it mysql5</span><span style="color:#F78C6C;">.7.3</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456</span></span></code></pre></div><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">change master to master_host=&#39;192.168.22.145&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_user=&#39;root&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_password=&#39;123456&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_port=3307, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_log_file=&#39;mall-mysql-bin.000002&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_log_pos=154, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_connect_retry=30;</span></span></code></pre></div><p>主从复制命令参数说明</p><ul><li>master_host：主数据库的IP地址；</li><li>master_port：主数据库的运行端口；</li><li>master_user：在主数据库创建的用于同步数据的用户账号；</li><li>master_password：在主数据库创建的用于同步数据的用户密码；</li><li>master_log_file：指定从数据库要复制数据的日志文件，通过查看主数据的状态，获取File参数；</li><li>master_log_pos：指定从数据库从哪个位置开始复制数据，通过查看主数据的状态，获取Position参数；</li><li>master_connect_retry：连接失败重试的时间间隔，单位为秒。</li></ul><p>在从数据库中开启主从同步</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">start slave</span><span style="color:#89DDFF;">;</span></span></code></pre></div><p>查看从数据库状态发现已经同步</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show slave status </span><span style="color:#89DDFF;">\</span><span style="color:#A6ACCD;">G</span><span style="color:#89DDFF;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209171632017.png" alt="image-20220917163234910" style="zoom:80%;"><h2 id="主从复制测试" tabindex="-1">主从复制测试 <a class="header-anchor" href="#主从复制测试" aria-label="Permalink to &quot;主从复制测试&quot;">​</a></h2><p>主机新建库-使用库-新建表-插入数据，ok</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">create</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">database</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">ph3</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#F78C6C;">use</span><span style="color:#A6ACCD;"> ph3;</span></span>
<span class="line"><span style="color:#F78C6C;">create</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">table</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">author</span><span style="color:#A6ACCD;"> (</span></span>
<span class="line"><span style="color:#A6ACCD;">    id </span><span style="color:#C792EA;">int</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">11</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">primary key</span><span style="color:#A6ACCD;"> auto_increment,</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F78C6C;">name</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">250</span><span style="color:#A6ACCD;">),</span></span>
<span class="line"><span style="color:#A6ACCD;">    country </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">250</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#F78C6C;">insert into</span><span style="color:#A6ACCD;"> author </span><span style="color:#F78C6C;">values</span><span style="color:#A6ACCD;"> (</span><span style="color:#F78C6C;">null</span><span style="color:#A6ACCD;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">村上春树</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">日本</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#F78C6C;">insert into</span><span style="color:#A6ACCD;"> author </span><span style="color:#F78C6C;">values</span><span style="color:#A6ACCD;"> (</span><span style="color:#F78C6C;">null</span><span style="color:#A6ACCD;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">莫言</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">中国</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#F78C6C;">insert into</span><span style="color:#A6ACCD;"> author </span><span style="color:#F78C6C;">values</span><span style="color:#A6ACCD;"> (</span><span style="color:#F78C6C;">null</span><span style="color:#A6ACCD;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">冯唐</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">中国</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">);</span></span></code></pre></div><p>从机使用库-查看记录，ok</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">use</span><span style="color:#A6ACCD;"> ph3;</span></span>
<span class="line"><span style="color:#F78C6C;">select</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">from</span><span style="color:#A6ACCD;"> author;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220209115009974.png" alt="image-20220209115009974" style="zoom:80%;"><h1 id="数据库迁移工具" tabindex="-1">数据库迁移工具 <a class="header-anchor" href="#数据库迁移工具" aria-label="Permalink to &quot;数据库迁移工具&quot;">​</a></h1><p><a href="https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==&amp;mid=2247488603&amp;idx=1&amp;sn=a41d446aa061833c15f45f5c7c5b34c7&amp;chksm=fc2fa853cb5821458d0c5fa3dc0238c7838f72928087c98467d0ca554d5533a046984d71e33e&amp;mpshare=1&amp;scene=23&amp;srcid=0812syBdoLDotnnSdT7yJl10&amp;sharer_sharetime=1660275406289&amp;sharer_shareid=29b8a04db1dbd975e3bf4e9f47e7ac67#rd" target="_blank" rel="noreferrer">数据库迁移搞炸了！没用这款开源神器的锅？ (qq.com)</a></p><blockquote><p>当我们的应用升级时往往会伴随着数据库表结构的升级，此时就需要迁移数据库的表结构。一般我们会使用工具或者脚本来实现，手动操作毕竟有一定风险，要是能在应用启动时自动升级数据库表结构就好了！Flyway正是这么一款工具，通过Flyway和SpringBoot结合使用，在应用启动时就可以自动升级数据库表结构，非常方便，推荐给大家！官方文档：<a href="https://flywaydb.org/documentation/" target="_blank" rel="noreferrer">https://flywaydb.org/documentation/</a></p></blockquote><h2 id="flyway简介" tabindex="-1">Flyway简介 <a class="header-anchor" href="#flyway简介" aria-label="Permalink to &quot;Flyway简介&quot;">​</a></h2><p>Flyway是一款数据库迁移工具，它让数据库迁移变得更加简单。它能像Git一样对数据库进行版本控制，支持命令行工具、Maven插件、第三方工具（比如SpringBoot）等多种使用方式。</p><p>Flyway具有如下特点：</p><ul><li>简单：使用和学习简单，通过不同版本的SQL脚本实现数据库迁移。</li><li>专业：专注于数据库迁移功能，你无需担心有任何问题。</li><li>功能强大：支持多种数据库，拥有大量的第三方工具，支持CI/DI。</li></ul><h2 id="相关概念" tabindex="-1">相关概念 <a class="header-anchor" href="#相关概念" aria-label="Permalink to &quot;相关概念&quot;">​</a></h2><h3 id="工作原理" tabindex="-1">工作原理 <a class="header-anchor" href="#工作原理" aria-label="Permalink to &quot;工作原理&quot;">​</a></h3><p>使用Flyway时我们需要编写好数据库迁移的SQL脚本，比如<code>V1__Initial_Setup.sql</code>中初始化了三种表，<code>V2__First_Changes.sql</code>中又新增了两种表。Flyway会创建<code>flyway_schema_history</code>表，用于存储这些SQL脚本的执行情况，从而对数据库进行版本控制。当我们使用Flyway进行数据库迁移时，Flyway会根据<code>flyway_schema_history</code>表中的记录，自行决定需要执行哪些SQL脚本，从而实现数据库迁移。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141844580.png" alt="image-20220814184424491" style="zoom:67%;"><h3 id="脚本命名规范" tabindex="-1">脚本命名规范 <a class="header-anchor" href="#脚本命名规范" aria-label="Permalink to &quot;脚本命名规范&quot;">​</a></h3><p>在创建Flyway的SQL脚本时，有些命名规范需要遵守，这些命名规范决定了Flyway执行脚本的顺序和方式，可以先参考下面的示意图。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141844367.png" alt="image-20220814184440305" style="zoom:67%;"><p>为了能被Flyway正确执行，SQL迁移脚本需要遵循如下规范：</p><ul><li>Prefix（前缀）：<code>V</code>表示有版本号的数据库迁移，<code>U</code>表示一些数据库版本的回滚，<code>R</code>表示可重复执行的数据库迁移；</li><li>Version（版本号）：Flyway会按照版本号的大小顺序来执行数据库迁移脚本；</li><li>Separator（分隔符）：命名时使用双下划线分隔符；</li><li>Description（描述）：用于描述该迁移脚本的具体操作说明；</li><li>Suffix（后缀）：表示<code>.sql</code>文件。</li></ul><h3 id="相关命令" tabindex="-1">相关命令 <a class="header-anchor" href="#相关命令" aria-label="Permalink to &quot;相关命令&quot;">​</a></h3><ul><li>migrate：数据库迁移命令，会根据设置好的SQL脚本直接将数据库表升级至最新版本。</li><li>clean：删除数据库中所有的表，千万别在生产环境上使用。</li><li>info：打印所有关于数据库迁移的详细信息和状态信息。</li><li>validate：验证数据库迁移是否可用。</li><li>undo：对数据库迁移进行回滚操作。</li><li>baseline：以现有数据库为基准，创建<code>flyway_schema_history</code>表，大于基准版本的数据库迁移才会被应用。</li><li>repair：修复<code>flyway_schema_history</code>表。</li></ul><h2 id="命令行工具" tabindex="-1">命令行工具 <a class="header-anchor" href="#命令行工具" aria-label="Permalink to &quot;命令行工具&quot;">​</a></h2><blockquote><p>使用Flyway实现数据迁移有多种方式，我们先通过命令行工具的方法来体验下Flyway的使用。</p></blockquote><p>首先需要下载Flyway的命令行工具，下载社区版即可，下载地址：<a href="https://flywaydb.org/download" target="_blank" rel="noreferrer">https://flywaydb.org/download</a></p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141845927.png" alt="image-20220814184534838" style="zoom:67%;"><p>下载完成后进行解压，解压完成后目录结构如下；</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141846411.png" alt="image-20220814184623341" style="zoom:67%;"><p>修改Flyway的配置文件<code>/conf/flyway.conf</code>，修改下数据库配置即可；</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">flyway</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">url</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">jdbc:mysql:</span><span style="color:#89DDFF;">//</span><span style="color:#A6ACCD;">localhost:</span><span style="color:#F78C6C;">3306</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">flyway</span><span style="color:#89DDFF;">?</span><span style="color:#A6ACCD;">useUnicode</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true</span><span style="color:#89DDFF;">&amp;</span><span style="color:#A6ACCD;">characterEncoding</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">utf</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">8</span><span style="color:#89DDFF;">&amp;</span><span style="color:#A6ACCD;">serverTimezone</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">Asia</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">Shanghai </span></span>
<span class="line"><span style="color:#A6ACCD;">flyway</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">user</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">root</span></span>
<span class="line"><span style="color:#A6ACCD;">flyway</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">password</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">root</span></span></code></pre></div><p>在<code>/sql</code>目录下添加SQL执行脚本，这里添加创建<code>ums_admin</code>表的执行脚本<code>V1.0.1__Create_ums_admin_table.sql</code>；</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">CREATE</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">TABLE</span><span style="color:#A6ACCD;"> `</span><span style="color:#82AAFF;">ums_admin</span><span style="color:#A6ACCD;">`</span></span>
<span class="line"><span style="color:#A6ACCD;">(</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">          </span><span style="color:#C792EA;">bigint</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">20</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> AUTO_INCREMENT,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">username</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">    </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">64</span><span style="color:#A6ACCD;">)  </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">password</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">    </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">64</span><span style="color:#A6ACCD;">)  </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">icon</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">500</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">头像</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">email</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">       </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">100</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">邮箱</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">nick_name</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">   </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">200</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">昵称</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">note</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">500</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">备注信息</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">create_time</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">datetime</span><span style="color:#A6ACCD;">     </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">创建时间</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">login_time</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">  </span><span style="color:#F78C6C;">datetime</span><span style="color:#A6ACCD;">     </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">最后登录时间</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">status</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">      </span><span style="color:#C792EA;">int</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">)       </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">1</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">帐号启用状态：0-&gt;禁用；1-&gt;启用</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#C792EA;">PRIMARY KEY</span><span style="color:#A6ACCD;"> (</span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">) ENGINE </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> InnoDB</span></span>
<span class="line"><span style="color:#A6ACCD;">  AUTO_INCREMENT </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">8</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> CHARSET </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> utf8 COMMENT </span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">后台用户表</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><ul><li>使用<code>flyway migrate</code>命令进行数据迁移，此时我们会发现需要先使用<code>flyway baseline</code>命令创建保存迁移记录的表<code>flyway_schema_history</code>才行；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwkD6LiaaNyMnSlTEOgIZrXz5Ptg33NxXiahjwc5O9Povem3PM5j7VdKaLUMfuTZia3bibLZvy9SxzXZxg/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>先使用<code>flyway baseline</code>命令，再使用<code>flyway migrate</code>命令，命令行会输出执行成功的信息；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwkD6LiaaNyMnSlTEOgIZrXz5qP9TAgTpsAmLMIrEtFZnicJibOvV0x8a8cECCOZSicnONk55eiawdS6LxQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>在<code>\sql</code>目录下添加SQL执行脚本，给<code>ums_admin</code>表添加一些数据，执行脚本为<code>V1.0.2__Add_ums_admin.sql</code>；</li></ul><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">INSERT INTO</span><span style="color:#A6ACCD;"> ums_admin (username, </span><span style="color:#F78C6C;">PASSWORD</span><span style="color:#A6ACCD;">, email, nick_name, </span><span style="color:#F78C6C;">STATUS</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#F78C6C;">VALUES</span><span style="color:#A6ACCD;"> (</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">test</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">test@qq.com</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">测试账号</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#F78C6C;">INSERT INTO</span><span style="color:#A6ACCD;"> ums_admin (username, </span><span style="color:#F78C6C;">PASSWORD</span><span style="color:#A6ACCD;">, email, nick_name, </span><span style="color:#F78C6C;">STATUS</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#F78C6C;">VALUES</span><span style="color:#A6ACCD;"> (</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">macro</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">macro@qq.com</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">普通账号</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#F78C6C;">INSERT INTO</span><span style="color:#A6ACCD;"> ums_admin (username, </span><span style="color:#F78C6C;">PASSWORD</span><span style="color:#A6ACCD;">, email, nick_name, </span><span style="color:#F78C6C;">STATUS</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#F78C6C;">VALUES</span><span style="color:#A6ACCD;"> (</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">andy</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">andy@qq.com</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">普通账号</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">, </span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">);</span></span></code></pre></div><ul><li>我们可以使用<code>flyway info</code>命令查看<code>flyway_schema_history</code>表中的数据迁移记录，可以发现<code>1.0.2</code>版本的更新还处于<code>Pending</code>状态，使用<code>flyway migrate</code>命令后变为<code>Success</code>；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwkD6LiaaNyMnSlTEOgIZrXz5m2ricmjjzXFkh94ASpc5BFWV1sGXbxOGf0fJicIe0z0xZvYtl4Unbf7w/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>我们可以创建可重复执行的SQL脚本，通常可以用来创建视图、存储过程、函数等，比如基于<code>ums_admin</code>表创建一个视图，执行脚本为<code>R__Ums_admin_view.sql</code>;</li></ul><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">CREATE</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F78C6C;">OR</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">REPLACE</span><span style="color:#A6ACCD;"> VIEW ums_admin_view </span><span style="color:#F78C6C;">AS</span></span>
<span class="line"><span style="color:#F78C6C;">SELECT</span><span style="color:#A6ACCD;"> username,</span></span>
<span class="line"><span style="color:#A6ACCD;">       </span><span style="color:#F78C6C;">PASSWORD</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">       email</span></span>
<span class="line"><span style="color:#F78C6C;">FROM</span><span style="color:#A6ACCD;"> ums_admin;</span></span></code></pre></div><ul><li>使用<code>flyway migrate</code>命令可以重复执行（当R开头的脚本有变更时），该脚本会在所有<code>V</code>开头的脚本执行完成后执行；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwkD6LiaaNyMnSlTEOgIZrXz5xHZsrnibnx1fxvTlzwtfM778Evv2liaFKWNBkFwqFcUjlHqj71S0u0ng/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>Flyway的回滚机制需要依赖SQL脚本，这里创建<code>U1.0.1__Create_ums_admin_table.sql</code>和<code>U1.0.2__Add_ums_admin.sql</code>两个回滚脚本；</li></ul><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># U1.0.1__Create_ums_admin_table.sql</span></span>
<span class="line"><span style="color:#F78C6C;">DROP</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">TABLE</span><span style="color:#A6ACCD;"> ums_admin</span></span>
<span class="line"><span style="color:#A6ACCD;"># U1.0.2__Add_ums_admin.sql</span></span>
<span class="line"><span style="color:#F78C6C;">DELETE</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">FROM</span><span style="color:#A6ACCD;"> ums_admin;</span></span></code></pre></div><ul><li>使用<code>flyway undo</code>命令可以执行回滚，很遗憾的是社区版本不支持回滚，看样子数据库升级之前还是得通过工具做好备份才行！</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwkD6LiaaNyMnSlTEOgIZrXz5xbXzl1O6vYefHxw6UYwjFQQs7jQ6Uic82HHLdpke3iapqoSNDP0oSdRg/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h2 id="maven插件" tabindex="-1">Maven插件 <a class="header-anchor" href="#maven插件" aria-label="Permalink to &quot;Maven插件&quot;">​</a></h2><blockquote><p>Flyway也提供了Maven插件，插件所支持功能与命令行工具基本一致。</p></blockquote><ul><li>想要在Maven项目通过插件使用Flyway，首先需要在pom.xml中添加Flyway的插件并配置好数据库连接信息；</li></ul><div class="language-xml"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">&lt;!--Flyway的Maven插件--&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">plugin</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">org.flywaydb</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">flyway-maven-plugin</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">7.3.2</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">configuration</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">url</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">jdbc:mysql://localhost:3306/flyway?serverTimezone=Asia/Shanghai</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">url</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">user</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">root</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">user</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">password</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">root</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">password</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">configuration</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependencies</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">mysql-connector-java</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">8.0.15</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependencies</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">plugin</span><span style="color:#89DDFF;">&gt;</span></span></code></pre></div><ul><li>在resouce目录下创建<code>db\migration</code>目录，将数据库升级使用的SQL脚本放入进去；</li></ul><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141847072.png" alt="image-20220814184746003" style="zoom:50%;"><ul><li>Flyway的Maven插件支持如下几种命令；</li></ul><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141848640.png" alt="image-20220814184801549" style="zoom:50%;"><ul><li>双击<code>flyway:info</code>命令使用，输出如下内容，此方式与命令行工具使用基本没啥区别。</li></ul><h2 id="结合springboot使用" tabindex="-1">结合SpringBoot使用 <a class="header-anchor" href="#结合springboot使用" aria-label="Permalink to &quot;结合SpringBoot使用&quot;">​</a></h2><blockquote><p>由于SpringBoot官方已经支持了Flyway，所以Flyway结合SpringBoot使用非常简单！</p></blockquote><ul><li>首先在pom.xml中添加Flyway相关依赖，注意无需添加Flyway的版本号：</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">&lt;!--Flyway相关依赖--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">&lt;dependency&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    &lt;groupId&gt;org.flywaydb&lt;/groupId&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    &lt;artifactId&gt;flyway-core&lt;/artifactId&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">&lt;/dependency&gt;</span></span></code></pre></div><ul><li>修改配置文件<code>application.yml</code>，对数据源和Flyway进行配置；</li></ul><div class="language-yml"><button title="Copy Code" class="copy"></button><span class="lang">yml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">spring</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">datasource</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">url</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">jdbc:mysql://localhost:3306/flyway?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">username</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">root</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">password</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">root</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">flyway</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 启用Flyway功能</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">enabled</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">true</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 禁用Flyway的clean命令，使用clean命令会删除schema下的所有表</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">clean-disabled</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">true</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 设置Flyway的SQL脚本路径</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">locations</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">classpath:db/migration</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 设置版本信息控制表名称，默认flyway_schema_history</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">table</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">flyway_schema_history</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 在执行migrate命令时需要有flyway_schema_history表，通过baseline命令可以生成该表</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">baseline-on-migrate</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">true</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 指定baseline版本号，低于该版本的SQL脚本在migrate是不会执行</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">baseline-version</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">1</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 设置字符编码</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">encoding</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">UTF-8</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 不允许不按顺序迁移</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">out-of-order</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">false</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 设置Flyway管控的schema，不设置的话为datasourcel.url中指定的schema</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">schemas</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">flyway</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 执行migrate时开启校验</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">validate-on-migrate</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">true</span></span></code></pre></div><p>最后直接运行SpringBoot应用，即可自动创建好对应的数据库，控制台会输出如下信息。</p><h1 id="数据库文档生成⭐" tabindex="-1">数据库文档生成⭐ <a class="header-anchor" href="#数据库文档生成⭐" aria-label="Permalink to &quot;数据库文档生成⭐&quot;">​</a></h1><blockquote><p>大家好，我是 Guide，今天分享一个好用的数据库文档生成工具。在项目中，我们经常需要整理数据库表结构文档。一般情况下，我们都是手动整理数据库表结构文档，当表结构有变动的时候，自己手动进行维护。数据库表少的时候还好，数据库表多了之后，手动整理和维护数据库表结构文档简直不要太麻烦，而且，还非常容易出错！</p></blockquote><blockquote><p>**有没有什么好用的工具帮助我们自动生成数据库表结构文档呢？**当然有！Github 上就有一位朋友开源了一款数据库表结构文档自动生成工具—— <strong>screw</strong> 。项目地址：<a href="https://github.com/pingfangushi/screw" target="_blank" rel="noreferrer">https://github.com/pingfangushi/screw</a> 。</p></blockquote><img src="https://mmbiz.qpic.cn/mmbiz_png/iaIdQfEric9TzqRXJ6dYEnWic3y3J2U7icks3dnahYE6KwWSCNgga0ZV6xOocIeblqMeXyAbRnMmvgJycNAoqeQ9zw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片" style="zoom:67%;"><blockquote><p>screw 翻译过来的意思就是螺丝钉，作者希望这个工具能够像螺丝钉一样切实地帮助到我们的开发工作。目前的话，screw 已经支持市面上大部分常见的数据库比如 MySQL、MariaDB、Oracle、SqlServer、PostgreSQL、TiDB。另外，screw 使用起来也非常简单，根据官网提示，不用 10 分钟就能成功在本地使用起来！</p></blockquote><h2 id="数据准备" tabindex="-1">数据准备 <a class="header-anchor" href="#数据准备" aria-label="Permalink to &quot;数据准备&quot;">​</a></h2><p>为了验证 screw 自动生成数据库表结构文档的效果，我们首先创建一个简单的存放博客数据的数据库表。</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">use</span><span style="color:#A6ACCD;"> xuexi;</span></span>
<span class="line"><span style="color:#F78C6C;">CREATE</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">TABLE</span><span style="color:#A6ACCD;"> `</span><span style="color:#82AAFF;">blog</span><span style="color:#A6ACCD;">` (</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">bigint</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">20</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> AUTO_INCREMENT COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">主键</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">title</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">255</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">博客标题</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">content</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> longtext </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">博客内容</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">description</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">255</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">博客简介</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">cover</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">varchar</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">255</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">博客封面图片地址</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">views</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">int</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">11</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">0</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">博客阅读次数</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">user_id</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">bigint</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">20</span><span style="color:#A6ACCD;">) </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">0</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">发表博客的用户ID</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">channel_id</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">bigint</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">20</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">博客分类ID</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">recommend</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">bit</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> b</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">0</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">是否推荐</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">top</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">bit</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> b</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">0</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">是否置顶</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">comment</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">bit</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">) </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> b</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">1</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">是否开启评论</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">created_at</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">timestamp</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> CURRENT_TIMESTAMP COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">创建时间</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">updated_at</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">timestamp</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NOT NULL</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> CURRENT_TIMESTAMP COMMENT </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">更新时间</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#C792EA;">PRIMARY KEY</span><span style="color:#A6ACCD;"> (</span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">`</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">) ENGINE</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">InnoDB AUTO_INCREMENT</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">16</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">DEFAULT</span><span style="color:#A6ACCD;"> CHARSET</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">utf8mb4 COMMENT</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">博客</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><h2 id="基于-java-代码" tabindex="-1">基于 Java 代码 <a class="header-anchor" href="#基于-java-代码" aria-label="Permalink to &quot;基于 Java 代码&quot;">​</a></h2><h3 id="引入依赖" tabindex="-1">引入依赖 <a class="header-anchor" href="#引入依赖" aria-label="Permalink to &quot;引入依赖&quot;">​</a></h3><p>创建一个普通的 Maven 项目即可！然后引入 screw、HikariCP、MySQL 这 3 个依赖。</p><div class="language-xml"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">&lt;!--screw--&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">cn.smallbun.screw</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">screw-core</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">1.0.5</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">&lt;!-- HikariCP --&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">com.zaxxer</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">HikariCP</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">3.4.5</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">&lt;!--MySQL--&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">mysql-connector-java</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span></code></pre></div><p>你可以通过下面的地址在 mvnrepository 获取最新版本的 screw。</p><blockquote><p><a href="https://mvnrepository.com/artifact/cn.smallbun.screw/screw-core" target="_blank" rel="noreferrer">https://mvnrepository.com/artifact/cn.smallbun.screw/screw-core</a></p></blockquote><h3 id="编写代码" tabindex="-1">编写代码 <a class="header-anchor" href="#编写代码" aria-label="Permalink to &quot;编写代码&quot;">​</a></h3><div class="language-java"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#C792EA;">public</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">class</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">t1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#C792EA;">public</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">static</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">void</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">main</span><span style="color:#89DDFF;">(</span><span style="color:#C792EA;">String</span><span style="color:#89DDFF;">[]</span><span style="color:#A6ACCD;"> </span><span style="color:#A6ACCD;font-style:italic;">args</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#82AAFF;">documentGeneration</span><span style="color:#89DDFF;">();</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#C792EA;">public</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">static</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">void</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">documentGeneration</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//数据源</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">HikariConfig</span><span style="color:#A6ACCD;"> hikariConfig </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">HikariConfig</span><span style="color:#89DDFF;">();</span></span>
<span class="line"><span style="color:#A6ACCD;">        hikariConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">setDriverClassName</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">com.mysql.cj.jdbc.Driver</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        hikariConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">setJdbcUrl</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">jdbc:mysql://127.0.0.1:3307/xuexi</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        hikariConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">setUsername</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">root</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        hikariConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">setPassword</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//设置可以获取tables remarks信息</span></span>
<span class="line"><span style="color:#A6ACCD;">        hikariConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">addDataSourceProperty</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">useInformationSchema</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">true</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        hikariConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">setMinimumIdle</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        hikariConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">setMaximumPoolSize</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">DataSource</span><span style="color:#A6ACCD;"> dataSource </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">HikariDataSource</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">hikariConfig</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//生成配置</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">EngineConfig</span><span style="color:#A6ACCD;"> engineConfig </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> EngineConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">builder</span><span style="color:#89DDFF;">()</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//生成文件路径</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">fileOutputDir</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">D:</span><span style="color:#A6ACCD;">\\</span><span style="color:#C3E88D;">SpringBoot新项目</span><span style="color:#A6ACCD;">\\</span><span style="color:#C3E88D;">demo</span><span style="color:#A6ACCD;">\\</span><span style="color:#C3E88D;">doc</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//打开目录</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">openOutputDir</span><span style="color:#89DDFF;">(true)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//文件类型</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">fileType</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">EngineFileType</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">HTML</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//生成模板实现</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">produceType</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">EngineTemplateType</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">freemarker</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//自定义文件名称</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">fileName</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">自定义文件名称</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">).</span><span style="color:#82AAFF;">build</span><span style="color:#89DDFF;">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//忽略表，有就忽略，没有就不管</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;</span><span style="color:#C792EA;">String</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> ignoreTableName </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;&gt;();</span></span>
<span class="line"><span style="color:#A6ACCD;">        ignoreTableName</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">add</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">blog</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        ignoreTableName</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">add</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">user</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//忽略表前缀，有就忽略，没有就不管</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;</span><span style="color:#C792EA;">String</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> ignorePrefix </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;&gt;();</span></span>
<span class="line"><span style="color:#A6ACCD;">        ignorePrefix</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">add</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">test_</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//忽略表后缀，有就忽略，没有就不管</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;</span><span style="color:#C792EA;">String</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> ignoreSuffix </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;&gt;();</span></span>
<span class="line"><span style="color:#A6ACCD;">        ignoreSuffix</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">add</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">_test</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">);</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">ProcessConfig</span><span style="color:#A6ACCD;"> processConfig </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> ProcessConfig</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">builder</span><span style="color:#89DDFF;">()</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时，</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//将生成指定表，其余表不生成、并跳过忽略表配置</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//根据名称指定表生成</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">designatedTableName</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;&gt;())</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//根据表前缀生成</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">designatedTablePrefix</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;&gt;())</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//根据表后缀生成</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">designatedTableSuffix</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">ArrayList</span><span style="color:#89DDFF;">&lt;&gt;())</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//忽略表名</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">ignoreTableName</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">ignoreTableName</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//忽略表前缀</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">ignoreTablePrefix</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">ignorePrefix</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//忽略表后缀</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">ignoreTableSuffix</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">ignoreSuffix</span><span style="color:#89DDFF;">).</span><span style="color:#82AAFF;">build</span><span style="color:#89DDFF;">();</span></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//配置</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#C792EA;">Configuration</span><span style="color:#A6ACCD;"> config </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> Configuration</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">builder</span><span style="color:#89DDFF;">()</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//版本</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">version</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">1.0.0</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//描述</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">description</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">数据库设计文档生成</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//数据源</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">dataSource</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">dataSource</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//生成配置</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">engineConfig</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">engineConfig</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">                </span><span style="color:#676E95;font-style:italic;">//生成配置</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">produceConfig</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">processConfig</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">build</span><span style="color:#89DDFF;">();</span></span>
<span class="line"><span style="color:#89DDFF;">        </span><span style="color:#676E95;font-style:italic;">//执行生成</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;font-style:italic;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">DocumentationExecute</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">config</span><span style="color:#89DDFF;">).</span><span style="color:#82AAFF;">execute</span><span style="color:#89DDFF;">();</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span></code></pre></div><p>下图就是生成的 HTML 格式的数据库设计文档。</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/iaIdQfEric9TzqRXJ6dYEnWic3y3J2U7icksLsIxcBkzt61dy2OwsZ2axCUOMpHl3WUyxLT6okSiaqv0flGH05D47uw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h2 id="基于-maven-插件⭐" tabindex="-1">基于 Maven 插件⭐ <a class="header-anchor" href="#基于-maven-插件⭐" aria-label="Permalink to &quot;基于 Maven 插件⭐&quot;">​</a></h2><p>除了基于 Java 代码这种方式之外，你还可以通过 screw 提供的 Maven 插件来生成数据库文档。方法也非常简单！</p><h3 id="_1、配置-maven-插件" tabindex="-1">1、配置 Maven 插件 <a class="header-anchor" href="#_1、配置-maven-插件" aria-label="Permalink to &quot;1、配置 Maven 插件&quot;">​</a></h3><p>务必将数据库相关的配置修改成你自己的。</p><div class="language-xml"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">build</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">plugins</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">plugin</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">cn.smallbun.screw</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">screw-maven-plugin</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">1.0.5</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependencies</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!-- HikariCP --&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">com.zaxxer</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">HikariCP</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">3.4.5</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--mysql driver--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">mysql-connector-java</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">8.0.28</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependencies</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">configuration</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--username--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">username</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">root</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">username</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--password--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">password</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">123456</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">password</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--driver--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">driverClassName</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">com.mysql.cj.jdbc.Driver</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">driverClassName</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--jdbc url--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">jdbcUrl</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">jdbc:mysql://127.0.0.1:3306/javaguide-blog</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">jdbcUrl</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--生成文件类型--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">fileType</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">MD</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">fileType</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--打开文件输出目录--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">openOutputDir</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">true</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">openOutputDir</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--生成模板--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">produceType</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">freemarker</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">produceType</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--文档名称 为空时:将采用[数据库名称-描述-版本号]作为文档名称--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">fileName</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">数据库结构文档</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">fileName</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--描述--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">description</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">数据库设计文档生成</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">description</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--版本--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">${project.version}</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#676E95;font-style:italic;">&lt;!--标题--&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">title</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">数据库文档</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">title</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">configuration</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">executions</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">execution</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">phase</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">compile</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">phase</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">goals</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                        </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">goal</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">run</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">goal</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                    </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">goals</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">execution</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">            </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">executions</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">plugin</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">plugins</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">build</span><span style="color:#89DDFF;">&gt;</span></span></code></pre></div><h3 id="_2、手动执行生成数据库文档" tabindex="-1">2、手动执行生成数据库文档 <a class="header-anchor" href="#_2、手动执行生成数据库文档" aria-label="Permalink to &quot;2、手动执行生成数据库文档&quot;">​</a></h3><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.2.30/202301311835939.png" alt="image-20230131183537872" style="zoom:67%;"><p>我们这里指定生成的是 Markdown 格式</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/iaIdQfEric9TzqRXJ6dYEnWic3y3J2U7icksEyxqKgm5hG7UAsbakj0UKOPxbNR48OhmqyN7ia201XmbMbBww0eDszg/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h3 id="_3、生成文档" tabindex="-1">3、生成文档 <a class="header-anchor" href="#_3、生成文档" aria-label="Permalink to &quot;3、生成文档&quot;">​</a></h3><p>下图就是生成的 Markdown 格式的数据库设计文档，效果还是非常不错的！</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.2.30/202301311836506.png" alt="image-20230131183638419" style="zoom:67%;"><h3 id="_4、参数可选项⭐" tabindex="-1">4、参数可选项⭐ <a class="header-anchor" href="#_4、参数可选项⭐" aria-label="Permalink to &quot;4、参数可选项⭐&quot;">​</a></h3><h4 id="filetype生成文件类型" tabindex="-1">fileType生成文件类型 <a class="header-anchor" href="#filetype生成文件类型" aria-label="Permalink to &quot;fileType生成文件类型&quot;">​</a></h4><div class="language-xml"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">&lt;!--生成文件类型--&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">fileType</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">MD</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">fileType</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">&lt;!--生成文件类型--&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">fileType</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">HTML</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">fileType</span><span style="color:#89DDFF;">&gt;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.2.30/202301311839189.png" alt="image-20230131183945099" style="zoom:67%;"><h1 id="mysql脚本工具" tabindex="-1">MySQL脚本工具 <a class="header-anchor" href="#mysql脚本工具" aria-label="Permalink to &quot;MySQL脚本工具&quot;">​</a></h1><blockquote><p>对于正在运行的mysql 性能如何？参数设置的是否合理？账号设置的是否存在安全隐患？你是否了然于胸？俗话说工欲善其事，必先利其器，定期对你的MYSQL数据库进行一个体检，是保证数据库安全运行的重要手段。</p></blockquote><blockquote><p>影响数据库因素：<strong>SQL查询速度、服务器硬件、网卡流量、磁盘IO</strong></p></blockquote><h2 id="mysqltuner-pl" tabindex="-1">mysqltuner.pl <a class="header-anchor" href="#mysqltuner-pl" aria-label="Permalink to &quot;mysqltuner.pl&quot;">​</a></h2><blockquote><p>这是mysql一个常用的数据库性能诊断工具，主要检查参数设置的合理性<strong>包括日志文件、存储引擎、安全建议及性能分析</strong>。针对潜在的问题，给出改进的建议，是mysql优化的好帮手。在上一版本中，<strong>MySQLTuner支持MySQL / MariaDB / Percona Server的约300个指标</strong></p></blockquote><blockquote><p>项目地址：<a href="https://github.com/major/MySQLTuner-perl" target="_blank" rel="noreferrer">https://github.com/major/MySQLTuner-perl</a></p></blockquote><h3 id="下载-使用" tabindex="-1">下载 &amp; 使用 <a class="header-anchor" href="#下载-使用" aria-label="Permalink to &quot;下载 &amp; 使用&quot;">​</a></h3><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">wget</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl</span></span></code></pre></div><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">perl</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">mysqltuner.pl</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">--user=root</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--pass=123456</span><span style="color:#A6ACCD;">   </span><span style="color:#C3E88D;">--socket</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql/mysql.sock</span></span></code></pre></div><h3 id="报告分析" tabindex="-1">报告分析 <a class="header-anchor" href="#报告分析" aria-label="Permalink to &quot;报告分析&quot;">​</a></h3><p>1）重要关注[!!]（中括号有叹号的项）例如<code>[!!] Maximum possible memory usage: 4.8G (244.13% of installed RAM)</code>，表示内存已经严重用超了。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202303021513472.png" alt="image-20230302151308245" style="zoom:67%;"><p>2）关注最后给的建议“Recommendations ”。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202303021513485.png" alt="image-20230302151351286" style="zoom:67%;"><h2 id="tuning-primer-sh" tabindex="-1">tuning-primer.sh <a class="header-anchor" href="#tuning-primer-sh" aria-label="Permalink to &quot;tuning-primer.sh&quot;">​</a></h2><p>这是mysql的另一个优化工具，针于mysql的整体进行一个体检，对潜在的问题，给出优化的建议。</p><blockquote><p>项目地址：<a href="https://github.com/BMDan/tuning-primer.sh" target="_blank" rel="noreferrer">https://github.com/BMDan/tuning-primer.sh</a></p></blockquote><h3 id="下载-使用-1" tabindex="-1">下载 &amp; 使用 <a class="header-anchor" href="#下载-使用-1" aria-label="Permalink to &quot;下载 &amp; 使用&quot;">​</a></h3><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">wget</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">https://launchpad.net/mysql-tuning-primer/trunk/1.6-r1/+download/tuning-primer.sh</span></span></code></pre></div><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">show</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">variables</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%socket%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202303021506586.png" alt="image-20230302150617515" style="zoom:80%;"><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">bash</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tuning-primer.sh</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">all</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--user=root</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--pass=123456</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">--socket=/var/lib/mysql/mysql.sock</span></span></code></pre></div><h3 id="报告分析-1" tabindex="-1">报告分析 <a class="header-anchor" href="#报告分析-1" aria-label="Permalink to &quot;报告分析&quot;">​</a></h3><p>重点查看有红色告警的选项，根据建议结合自己系统的实际情况进行修改，例如：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202303021507445.png" alt="image-20230302150705314" style="zoom:80%;"><h2 id="pt-variable-advisor" tabindex="-1">pt-variable-advisor <a class="header-anchor" href="#pt-variable-advisor" aria-label="Permalink to &quot;pt-variable-advisor&quot;">​</a></h2><blockquote><p><strong><code>pt-variable-advisor</code></strong> 是 Percona 工具包中的一个工具，用于分析 MySQL 的配置文件以及运行时参数，并给出优化建议。它可以帮助你确定哪些变量应该被调整以优化 MySQL 的性能。</p></blockquote><h3 id="安装-使用" tabindex="-1">安装 &amp; 使用 <a class="header-anchor" href="#安装-使用" aria-label="Permalink to &quot;安装 &amp; 使用&quot;">​</a></h3><blockquote><p><a href="https://www.percona.com/downloads/percona-toolkit/LATEST/" target="_blank" rel="noreferrer">https://www.percona.com/downloads/percona-toolkit/LATEST/</a></p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">wget</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">https://www.percona.com/downloads/percona-toolkit/3.0.13/binary/redhat/7/x86_64/percona-toolkit-3.0.13-re85ce15-el7-x86_64-bundle.tar</span></span>
<span class="line"><span style="color:#FFCB6B;">yum</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">install</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">percona-toolkit-3.0.13-1.el7.x86_64.rpm</span></span></code></pre></div><p><code>pt-variable-advisor</code>是pt工具集的一个子工具，主要用来诊断你的参数设置是否合理。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">pt-variable-advisor localhost --socket /var/lib/mysql/mysql.sock</span></span></code></pre></div><h3 id="报告分析-2" tabindex="-1">报告分析 <a class="header-anchor" href="#报告分析-2" aria-label="Permalink to &quot;报告分析&quot;">​</a></h3><p>重点关注有WARN的信息的条目，例如：</p><p><img src="https://mmbiz.qpic.cn/mmbiz/8Jeic82Or04k265dJaKFFtmLTCGYTPiaaRrHqUnoVAiay0TfwluBsRhyMSibacic5CjYTaVCTjsdP1wdzlCHPOpEeibA/640?wx_fmt=jpeg&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;random=0.4055236122777566" alt="图片"></p><h2 id="pt-qurey-digest" tabindex="-1">pt-qurey-digest <a class="header-anchor" href="#pt-qurey-digest" aria-label="Permalink to &quot;pt-qurey-digest&quot;">​</a></h2><p><code>pt-query-digest</code> 主要功能是从日志、进程列表和tcpdump分析MySQL查询。</p><p>安装官网：<a href="http://www.ywnds.com/?p=8174" target="_blank" rel="noreferrer">http://www.ywnds.com/?p=8174</a></p><h3 id="安装-使用-1" tabindex="-1">安装 &amp; 使用 <a class="header-anchor" href="#安装-使用-1" aria-label="Permalink to &quot;安装 &amp; 使用&quot;">​</a></h3><p><code>pt-query-digest</code>主要用来分析mysql的慢日志，与<code>mysqldumpshow</code>工具相比，<code>py-query_digest </code>工具的分析结果更具体，更完善。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">pt-query-digest /var/lib/mysql/slowtest-slow.log</span></span></code></pre></div><blockquote><p>pt-query-digest 是分析MySQL查询日志最有力的工具，该工具功能强大，它可以分析binlog，Generallog，slowlog，也可以通过show processlist或者通过 tcpdump 抓取的MySQL协议数据来进行分析，比 mysqldumpslow 更具体</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 安装命令</span></span>
<span class="line"><span style="color:#A6ACCD;">yum install perl</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">IO</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">Socket</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">SSL perl</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">DBD</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">MySQL perl</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">Time</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">HiRes perl</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">TermReadKey perl</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">IO</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">Socket</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">SSL </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">y</span></span>
<span class="line"><span style="color:#A6ACCD;">yum localinstall https:</span><span style="color:#89DDFF;">//</span><span style="color:#A6ACCD;">www</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">percona</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">com</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">downloads</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">percona</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">toolkit</span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">2.2.20</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">RPM</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">percona</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">toolkit</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">2.2.20</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">noarch</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">rpm</span></span></code></pre></div><h3 id="基本使用" tabindex="-1">基本使用 <a class="header-anchor" href="#基本使用" aria-label="Permalink to &quot;基本使用&quot;">​</a></h3><div class="language-c"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">//直接分析慢查询文件</span></span>
<span class="line"><span style="color:#A6ACCD;">pt</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">query</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">digest  </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">slow.log </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">slow_report.log</span></span></code></pre></div><p>打开查看</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209222048701.png" alt="image-20220922204805635" style="zoom:80%;"><blockquote><p>该工具可以将查询的剖析报告打印出来，可以分析结果输出到文件中，分析过程是先对查询语句的条件进行参数化，然后对参数化以后的查询进行分组统计，统计出各查询的执行时间，次数，占比等，可以借助分析结果找出问题进行优化。</p></blockquote><h3 id="常见用法分析" tabindex="-1">常见用法分析 <a class="header-anchor" href="#常见用法分析" aria-label="Permalink to &quot;常见用法分析&quot;">​</a></h3><p>1）直接分析慢查询文件:</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">pt-query-digest</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql/slowtest-slow.log</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">slow_report.log</span></span></code></pre></div><p>2）分析最近12小时内的查询：</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">pt-query-digest</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--since=12h</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql/slowtest-slow.log</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">slow_report2.log</span></span></code></pre></div><p>3）分析指定时间范围内的查询：</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">pt-query-digest</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql/slowtest-slow.log</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--since</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">2017-01-07 09:30:00</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--until</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">2017-01-07 10:00:00</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">slow_report3.log</span></span></code></pre></div><p>4）分析指含有select语句的慢查询</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">pt-query-digest</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--filter</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">$event-&gt;{fingerprint} =~ m/^select/i</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql/slowtest-slow.lo</span><span style="color:#A6ACCD;">g</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">slow_report4.log</span></span></code></pre></div><p>5）针对某个用户的慢查询</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">pt-query-digest</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--filter</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">($event-&gt;{user} || &quot;&quot;) =~ m/^root/i</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql/slowtest-slow.lo</span><span style="color:#A6ACCD;">g</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">slow_report5.log</span></span></code></pre></div><p>6）查询所有所有的全表扫描或<code>full join</code>的慢查询</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">pt-query-digest</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--filter</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">(($event-&gt;{Full_scan} || &quot;&quot;) eq &quot;yes&quot;) ||(($event-&gt;{Full_join} || &quot;&quot;) eq &quot;yes&quot;)</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/mysql/slowtest-slow.lo</span><span style="color:#A6ACCD;">g</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">slow_report6.log</span></span></code></pre></div><h3 id="报告分析-3" tabindex="-1">报告分析 <a class="header-anchor" href="#报告分析-3" aria-label="Permalink to &quot;报告分析&quot;">​</a></h3><p><strong>第一部分：总体统计结果</strong></p><ul><li><code>Overall</code>：总共有多少条查询</li><li><code>Time range</code>：查询执行的时间范围</li><li><code>unique</code>：唯一查询数量，即对查询条件进行参数化以后，总共有多少个不同的查询</li><li><code>total</code>：总计 min：最小 max：最大 avg：平均</li><li><code>95%</code>：把所有值从小到大排列，位置位于95%的那个数，这个数一般最具有参考价值</li><li><code>median</code>：中位数，把所有值从小到大排列，位置位于中间那个数</li></ul><p><strong>第二部分：查询分组统计结果</strong></p><ul><li><code>Rank</code>：所有语句的排名，默认按查询时间降序排列，通过--order-by指定</li><li><code>Query ID</code>：语句的ID，（去掉多余空格和文本字符，计算hash值）</li><li><code>Response</code>：总的响应时间</li><li><code>time</code>：该查询在本次分析中总的时间占比</li><li><code>calls</code>：执行次数，即本次分析总共有多少条这种类型的查询语句</li><li><code>R/Call</code>：平均每次执行的响应时间</li><li><code>V/M</code>：响应时间Variance-to-mean的比率</li><li><code>Item</code>：查询对象</li></ul><p><strong>第三部分：每一种查询的详细统计结果</strong></p><p>由下面查询的详细统计结果，最上面的表格列出了执行次数、最大、最小、平均、95%等各项目的统计。</p><ul><li><code>ID</code>：查询的ID号，和上图的Query ID对应</li><li><code>Databases</code>：数据库名</li><li><code>Users</code>：各个用户执行的次数（占比）</li><li><code>Query_time distribution</code> ：查询时间分布, 长短体现区间占比，本例中1s-10s之间查询数量是10s以上的两倍。</li><li><code>Tables</code>：查询中涉及到的表</li><li><code>Explain</code>：SQL语句</li></ul><h1 id="navicat实用功能" tabindex="-1">Navicat实用功能 <a class="header-anchor" href="#navicat实用功能" aria-label="Permalink to &quot;Navicat实用功能&quot;">​</a></h1><h2 id="数据备份" tabindex="-1">数据备份 <a class="header-anchor" href="#数据备份" aria-label="Permalink to &quot;数据备份&quot;">​</a></h2><p><a href="https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==&amp;mid=2247483745&amp;idx=1&amp;sn=bae7a292d30f3da7e9792de392d7c0ca&amp;scene=21#wechat_redirect" target="_blank" rel="noreferrer">Navicat实用功能：数据备份与结构同步 (qq.com)</a></p><p>现在我们先对World数据库备份，备份完成后，删除表的数据，然后利用备份进行数据还原。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261415372.png" alt="image-20220526141550324" style="zoom:67%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261415520.png" alt="image-20220526141501458" style="zoom:67%;"><p>删除原数据表内容后，进行还原备份</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261416560.png" alt="image-20220526141658508" style="zoom:80%;"><h2 id="结构同步" tabindex="-1">结构同步 <a class="header-anchor" href="#结构同步" aria-label="Permalink to &quot;结构同步&quot;">​</a></h2><p>就是让不同数据库具有相同的表和表结构</p><p>原来的mall-test模块中只有商品模块的表，现在我们经过了一段时间的开发，新增了订单模块，同时删除和修改了商品模块的一些表，而mall-prod表中还是原来的商品模块表，我们现在要做的是把mall-test的数据库表结构同步到mall-prod。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261418765.png" alt="image-20220526141809716" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261419134.png" alt="image-20220526141901062" style="zoom:67%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261419035.png" alt="image-20220526141925957" style="zoom:67%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261419224.png" alt="image-20220526141947133" style="zoom:67%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261420139.png" alt="image-20220526142008070" style="zoom:67%;"><h2 id="数据同步" tabindex="-1">数据同步 <a class="header-anchor" href="#数据同步" aria-label="Permalink to &quot;数据同步&quot;">​</a></h2><p>上面只同步结构，这里选择同步数据</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261426133.png" alt="image-20220526142617084" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261424299.png" alt="image-20220526142423224" style="zoom:67%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261425752.png" alt="image-20220526142510701" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.5.13/202205261425978.png" alt="image-20220526142544925" style="zoom:67%;"><h2 id="数据生成" tabindex="-1">数据生成 <a class="header-anchor" href="#数据生成" aria-label="Permalink to &quot;数据生成&quot;">​</a></h2><p>这个神器就是我们日常使用的 Navicat，但是最低是要在16版本，之前的版本是没有这个功能的（其实是我没有低版本，懒得测试了，哈哈）进入 Navicat Premium 16 工具 -&gt; 数据生成</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171535715.png" alt="image-20230417153535640" style="zoom:67%;"><p>然后连接到数据库，选择你想造数据的表，选择需要造数据的字段，想造多少条都可以</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171536033.png" alt="image-20230417153605934" style="zoom:80%;"><blockquote><p>注意：这边不要写太大，写1000就行，下图太大生成就会出错</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171536039.png" alt="image-20230417153639971" style="zoom:80%;"><p>你还可以对每个字段都设置想要的生成规则，例如：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171537167.png" alt="image-20230417153717099" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171537554.png" alt="image-20230417153737483" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171539744.png" alt="image-20230417153952668" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171538314.png" alt="image-20230417153858251" style="zoom:80%;"><blockquote><p>预览效果</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202304171540549.png" alt="image-20230417154022466" style="zoom:80%;"><h1 id="定时备份数据方案-全库备份" tabindex="-1">定时备份数据方案（全库备份） <a class="header-anchor" href="#定时备份数据方案-全库备份" aria-label="Permalink to &quot;定时备份数据方案（全库备份）&quot;">​</a></h1><h2 id="如何选择备份工具" tabindex="-1">如何选择备份工具 <a class="header-anchor" href="#如何选择备份工具" aria-label="Permalink to &quot;如何选择备份工具&quot;">​</a></h2><p>根据备份的方法（是否需要数据库离线）可以将备份分为：</p><blockquote><ul><li>热备（Hot Backup）</li><li>冷备（Cold Backup）</li><li>温备（Warm Backup）</li></ul></blockquote><p>MySQL 中进行不同方式的备份还要考虑存储引擎是否支持，如 MyISAM 不支持热备，支持温备和冷备。而 InnoDB 支持热备、温备和冷备。一般情况下，我们需要备份的数据分为以下几种：</p><blockquote><ul><li>表数据</li><li>二进制日志、InnoDB 事务日志</li><li>代码（存储过程、存储函数、触发器、事件调度器）</li><li>服务器配置文件</li></ul></blockquote><p>下面是几种常用的备份工具：</p><blockquote><ul><li>mysqldump：逻辑备份工具，适用于所有的存储引擎，支持温备、完全备份、部分备份、对于 InnoDB 存储引擎支持热备。</li><li>cp、tar 等归档复制工具：物理备份工具，适用于所有的存储引擎、冷备、完全备份、部分备份。</li><li>lvm2 snapshot：借助文件系统管理工具进行备份。</li><li>mysqlhotcopy：名不副实的一个工具，仅支持 MyISAM 存储引擎。</li><li>xtrabackup：一款由 percona 提供的非常强大的 InnoDB/XtraDB 热备工具，支持完全备份、增量备份。</li></ul></blockquote><p>直接复制数据文件是最为直接、快速的备份方法，但缺点是基本上不能实现增量备份。备份时必须确保没有使用这些表。如果在复制一个表的同时服务器正在修改它，则复制无效。备份 文件时，最好关闭服务器，然后重新启动服务器。</p><h2 id="数据备份命令⭐" tabindex="-1">数据备份命令⭐ <a class="header-anchor" href="#数据备份命令⭐" aria-label="Permalink to &quot;数据备份命令⭐&quot;">​</a></h2><h3 id="命令分析" tabindex="-1">命令分析 <a class="header-anchor" href="#命令分析" aria-label="Permalink to &quot;命令分析&quot;">​</a></h3><p>在MySQL中提供了命令行导出数据库数据以及文件的一种方便的工具mysqldump,我们可以通过命令行直接实现数据库内容的导出dump,首先我们简单了解一下mysqldump命令用法:</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># MySQLdump常用</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">u </span><span style="color:#F78C6C;">root</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#676E95;font-style:italic;">--databases 数据库1 数据库2 &gt; xxx.sql</span></span></code></pre></div><h3 id="常用操作示例" tabindex="-1">常用操作示例 <a class="header-anchor" href="#常用操作示例" aria-label="Permalink to &quot;常用操作示例&quot;">​</a></h3><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">-- 1.备份全部数据库的数据和结构</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">A </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 2.备份全部数据库的结构（加 -d 参数）</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">A </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 3.备份全部数据库的数据(加 -t 参数)</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">A </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">t </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 4.备份单个数据库的数据和结构(数据库名mydb)</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 mydb </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 5.备份单个数据库的结构</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 mydb </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 6.备份单个数据库的数据</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 mydb </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">t </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 7.备份多个表的数据和结构（数据，结构的单独备份方法与上同）</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 mydb t1 t2 </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">-- 8.一次备份多个数据库</span></span>
<span class="line"><span style="color:#A6ACCD;">mysqldump </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 </span><span style="color:#676E95;font-style:italic;">--databases db1 db2 &gt; /data/mysqlDump/mydb.sql</span></span></code></pre></div><h3 id="还原备份内容" tabindex="-1">还原备份内容 <a class="header-anchor" href="#还原备份内容" aria-label="Permalink to &quot;还原备份内容&quot;">​</a></h3><p>有两种方式还原，第一种是在MySQL命令行中，第二种是使用SHELL行完成还原</p><p>1.在系统命令行中，输入如下实现还原：</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456 </span><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span></code></pre></div><p>2.在登录进入mysql系统中,通过source指令找到对应系统中的文件进行还原：</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> source </span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysqlDump</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydb.sql</span></span></code></pre></div><h2 id="脚本实现⭐" tabindex="-1">脚本实现⭐ <a class="header-anchor" href="#脚本实现⭐" aria-label="Permalink to &quot;脚本实现⭐&quot;">​</a></h2><p>在linux中，通常使用BASH脚本对需要执行的内容进行编写，加上定时执行命令crontab实现日志自动化生成。</p><p>以下代码功能就是针对mysql进行备份，配合crontab，实现备份的内容为近一个月（31天）内的每天的mysql数据库记录。</p><h3 id="编写bash维护固定数量备份文件" tabindex="-1">编写BASH维护固定数量备份文件 <a class="header-anchor" href="#编写bash维护固定数量备份文件" aria-label="Permalink to &quot;编写BASH维护固定数量备份文件&quot;">​</a></h3><p>在Linux中，使用vi或者vim编写脚本内容并命名为：<code>mysql_dump_script.sh</code></p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">#!/bin/bash</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#保存备份个数，备份31天数据</span></span>
<span class="line"><span style="color:#A6ACCD;">number</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">31</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#备份保存路径</span></span>
<span class="line"><span style="color:#A6ACCD;">backup_dir</span><span style="color:#89DDFF;">=</span><span style="color:#C3E88D;">/root/mysqlbackup</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#日期</span></span>
<span class="line"><span style="color:#A6ACCD;">dd</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">`</span><span style="color:#FFCB6B;">date</span><span style="color:#C3E88D;"> +%Y-%m-%d-%H-%M-%S</span><span style="color:#89DDFF;">`</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#备份工具</span></span>
<span class="line"><span style="color:#A6ACCD;">tool</span><span style="color:#89DDFF;">=</span><span style="color:#C3E88D;">mysqldump</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#用户名</span></span>
<span class="line"><span style="color:#A6ACCD;">username</span><span style="color:#89DDFF;">=</span><span style="color:#C3E88D;">root</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#密码</span></span>
<span class="line"><span style="color:#A6ACCD;">password</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">123456</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#将要备份的数据库</span></span>
<span class="line"><span style="color:#A6ACCD;">database_name</span><span style="color:#89DDFF;">=</span><span style="color:#C3E88D;">edoctor</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#如果文件夹不存在则创建</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">!</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-d</span><span style="color:#A6ACCD;"> $backup_dir </span><span style="color:#89DDFF;">];</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">then</span><span style="color:#A6ACCD;">     </span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">mkdir</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> $backup_dir</span><span style="color:#89DDFF;">;</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">fi</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 简单写法  mysqldump -u root -p123456 users &gt; /root/mysqlbackup/users-$filename.sql</span></span>
<span class="line"><span style="color:#A6ACCD;">$tool -u $username -p$password $database_name </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> $backup_dir/$database_name-$dd.sql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 写创建备份日志</span></span>
<span class="line"><span style="color:#82AAFF;">echo</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">create </span><span style="color:#A6ACCD;">$backup_dir</span><span style="color:#C3E88D;">/</span><span style="color:#A6ACCD;">$database_name</span><span style="color:#C3E88D;">-</span><span style="color:#A6ACCD;">$dd</span><span style="color:#C3E88D;">.dump</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;&gt;</span><span style="color:#A6ACCD;"> $backup_dir</span><span style="color:#C3E88D;">/log.txt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 找出需要删除的备份</span></span>
<span class="line"><span style="color:#A6ACCD;">delfile</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">`</span><span style="color:#FFCB6B;">ls</span><span style="color:#C3E88D;"> -l -crt  </span><span style="color:#A6ACCD;">$backup_dir</span><span style="color:#C3E88D;">/</span><span style="color:#A6ACCD;">*</span><span style="color:#C3E88D;">.sql </span><span style="color:#89DDFF;">|</span><span style="color:#C3E88D;"> </span><span style="color:#FFCB6B;">awk</span><span style="color:#C3E88D;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">{print $9 }</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;"> </span><span style="color:#89DDFF;">|</span><span style="color:#C3E88D;"> </span><span style="color:#FFCB6B;">head</span><span style="color:#C3E88D;"> -1</span><span style="color:#89DDFF;">`</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 判断现在的备份数量是否大于$number</span></span>
<span class="line"><span style="color:#A6ACCD;">count</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">`</span><span style="color:#FFCB6B;">ls</span><span style="color:#C3E88D;"> -l -crt  </span><span style="color:#A6ACCD;">$backup_dir</span><span style="color:#C3E88D;">/</span><span style="color:#A6ACCD;">*</span><span style="color:#C3E88D;">.sql </span><span style="color:#89DDFF;">|</span><span style="color:#C3E88D;"> </span><span style="color:#FFCB6B;">awk</span><span style="color:#C3E88D;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">{print $9 }</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;"> </span><span style="color:#89DDFF;">|</span><span style="color:#C3E88D;"> </span><span style="color:#FFCB6B;">wc</span><span style="color:#C3E88D;"> -l</span><span style="color:#89DDFF;">`</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;"> $count </span><span style="color:#89DDFF;">-gt</span><span style="color:#A6ACCD;"> $number </span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">then</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;">#删除最早生成的备份，只保留number数量的备份</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#FFCB6B;">rm</span><span style="color:#A6ACCD;"> $delfile</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;">#写删除文件日志</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#82AAFF;">echo</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">delete </span><span style="color:#A6ACCD;">$delfile</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;&gt;</span><span style="color:#A6ACCD;"> $backup_dir</span><span style="color:#C3E88D;">/log.txt</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">fi</span></span></code></pre></div><p>如上代码主要含义如下：</p><blockquote><p>1.首先设置各项参数，例如number最多需要备份的数目，备份路径，用户名，密码等。</p><p>2.执行mysqldump命令保存备份文件，并将操作打印至同目录下的log.txt中标记操作日志。</p><p>3.定义需要删除的文件：通过ls命令获取第九列，即文件名列，再通过</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">head </span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">1</span></span></code></pre></div><p>实现定义操作时间最晚的那个需要删除的文件。</p><p>4.定义备份数量：通过ls命令加上</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">wc </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">l</span></span></code></pre></div><p>统计以sql结尾的文件的行数。</p><p>5.如果文件超出限制大小，就删除最早创建的sql文件</p><h3 id="使用crontab定期执行备份脚本" tabindex="-1">使用crontab定期执行备份脚本 <a class="header-anchor" href="#使用crontab定期执行备份脚本" aria-label="Permalink to &quot;使用crontab定期执行备份脚本&quot;">​</a></h3><p>在LINUX中，周期执行的任务一般由cron这个守护进程来处理<code>[ps -ef|grep cron]</code>。cron读取一个或多个配置文件，这些配置文件中包含了命令行及其调用时间。</p><p>cron的配置文件称为“crontab”，是“cron table”的简写。</p><h4 id="cron服务" tabindex="-1">cron服务 <a class="header-anchor" href="#cron服务" aria-label="Permalink to &quot;cron服务&quot;">​</a></h4><p>cron是一个linux下 的定时执行工具，可以在无需人工干预的情况下运行作业。</p><div class="language-c"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">service crond start</span><span style="color:#676E95;font-style:italic;">    //启动服务</span></span>
<span class="line"><span style="color:#A6ACCD;">service crond stop</span><span style="color:#676E95;font-style:italic;">     //关闭服务</span></span>
<span class="line"><span style="color:#A6ACCD;">service crond restart</span><span style="color:#676E95;font-style:italic;">  //重启服务</span></span>
<span class="line"><span style="color:#A6ACCD;">service crond reload</span><span style="color:#676E95;font-style:italic;">   //重新载入配置</span></span>
<span class="line"><span style="color:#A6ACCD;">service crond status</span><span style="color:#676E95;font-style:italic;">   //查看服务状态</span></span></code></pre></div><h4 id="crontab语法" tabindex="-1">crontab语法 <a class="header-anchor" href="#crontab语法" aria-label="Permalink to &quot;crontab语法&quot;">​</a></h4><blockquote><p>crontab命令用于安装、删除或者列出用于驱动cron后台进程的表格。用户把需要执行的命令序列放到crontab文件中以获得执行。每个用户都可以有自己的crontab文件。<code>/var/spool/cron</code>下的crontab文件不可以直接创建或者直接修改。该crontab文件是通过crontab命令创建的。</p></blockquote><blockquote><p>在crontab文件中如何输入需要执行的命令和时间。该文件中每行都包括六个域，其中前五个域是指定命令被执行的时间，最后一个域是要被执行的命令。</p></blockquote><p>每个域之间使用空格或者制表符分隔。格式如下：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">minute hour day</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">of</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">month month</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">of</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">year day</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">of</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">week commands</span></span></code></pre></div><p>合法值 <code>00-59 00-23 01-31 01-12 0-6 (0 is sunday)</code></p><p>除了数字还有几个个特殊的符号就是&quot;<code>*</code>&quot;、&quot;<code>/</code>&quot;和&quot;<code>-</code>&quot;、&quot;<code>,</code>&quot;，<code>*</code>代表所有的取值范围内的数字，&quot;<code>/</code>&quot;代表每的意思,&quot;<code>/5</code>&quot;表示每5个单位，&quot;<code>-</code>&quot;代表从某个数字到某个数字,&quot;<code>,</code>&quot;分开几个离散的数字。</p><ul><li><code>-l</code> 在标准输出上显示当前的crontab。</li><li><code>-r</code> 删除当前的crontab文件。</li><li><code>-e</code> 使用VISUAL或者EDITOR环境变量所指的编辑器编辑当前的crontab文件。当结束编辑离开时，编辑后的文件将自动安装。</li></ul><h4 id="创建cron脚本" tabindex="-1">创建cron脚本 <a class="header-anchor" href="#创建cron脚本" aria-label="Permalink to &quot;创建cron脚本&quot;">​</a></h4><p>第一步：写cron脚本文件,命名为mysqlRollBack.cron。</p><p><code>15,30,45,59 * * * * echo &quot;xgmtest.....&quot; &gt;&gt; xgmtest.txt</code> 表示，每隔15分钟，执行打印一次命令</p><p>第二步：添加定时任务。执行命令 “<code>crontab crontest.cron</code>”。搞定</p><p>第三步：&quot;<code>crontab -l</code>&quot; 查看定时任务是否成功或者检测<code>/var/spool/cron</code>下是否生成对应cron脚本</p><blockquote><p>注意：这操作是直接替换该用户下的crontab，而不是新增</p></blockquote><p>定期执行编写的定时任务脚本（记得先给shell脚本执行权限）</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">0</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">root</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql_backup_script</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">sh</span></span></code></pre></div><p>随后使用crontab命令定期指令编写的定时脚本</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">crontab mysqlRollback</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cron</span></span></code></pre></div><p>再通过命令检查定时任务是否已创建：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">crontab </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">l</span></span></code></pre></div><h4 id="执行效果截图" tabindex="-1">执行效果截图 <a class="header-anchor" href="#执行效果截图" aria-label="Permalink to &quot;执行效果截图&quot;">​</a></h4><p>以下是我的测试每分钟的截图效果，其对应代码如下：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">root</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql_backup_script</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">sh</span></span></code></pre></div><p>效果截图：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207291712639.png" alt="image-20220729171223513" style="zoom:67%;"><p>其中的log.txt记录备份的操作详细日志：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207291712064.png" alt="image-20220729171234990" style="zoom:80%;"><h1 id="监控状态指标-status" tabindex="-1">监控状态指标(status) <a class="header-anchor" href="#监控状态指标-status" aria-label="Permalink to &quot;监控状态指标(status)&quot;">​</a></h1><blockquote><p>MySQL Status提供服务器状态信息，是单纯的累计数（如重启就会重置），表面上只能体现多和少。但这些统计值，如zabbix，prometheus监控平台一样，通过某个时间间隔的差值，体现MySQL某种偏向的执行情况。比如临时表使用比较多，底层page交换频繁凡 等。Status统计信息是日常监控的部分核心数据，也是问题排查中非常有意义的参考数据。Status计数，不仅是监控需要的指标，也是日常排查问题的一种判断推理依据。</p></blockquote><p>语法</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">SHOW </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">GLOBAL </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> SESSION</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> STATUS </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">LIKE </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">pattern</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> WHERE expr</span><span style="color:#89DDFF;">]</span></span></code></pre></div><p>例子</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">status</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Com_insert</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">status</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">uptime</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><h2 id="查看所有状态" tabindex="-1">查看所有状态 <a class="header-anchor" href="#查看所有状态" aria-label="Permalink to &quot;查看所有状态&quot;">​</a></h2><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show  global status</span><span style="color:#89DDFF;">;</span></span></code></pre></div><h2 id="执行情况" tabindex="-1">执行情况 <a class="header-anchor" href="#执行情况" aria-label="Permalink to &quot;执行情况&quot;">​</a></h2><blockquote><p>性能指标（TPS，QPS）是衡量数据库的能力的一个标准。这些指标依据也是通过Status里计算的。 QPS（Queries Per Second，每秒查询数）=Com_select TPS（Transactions Per Second，每秒处理事务数）=Com_insert + Com_delete + Com_update</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221153866.png" alt="image-20220622115354787" style="zoom:67%;"><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 查看多个指标</span></span>
<span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">status</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Com_______</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221200051.png" alt="image-20220622120050987" style="zoom:67%;"><h2 id="sql质量情况" tabindex="-1">SQL质量情况 <a class="header-anchor" href="#sql质量情况" aria-label="Permalink to &quot;SQL质量情况&quot;">​</a></h2><p>对于mysql来说随着数据量增加 全表扫描，不使用索引，排序，回滚 这些现象对于MySQL是最致命的。大量消耗mysql处理能力，服务器资源（硬盘io，cpu资源 等）。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221154994.png" alt="image-20220622115424779" style="zoom:67%;"><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">status</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Slow%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><h2 id="临时表利用率" tabindex="-1">临时表利用率 <a class="header-anchor" href="#临时表利用率" aria-label="Permalink to &quot;临时表利用率&quot;">​</a></h2><p>临时表多，说明多表join产生大量的中间表，排序无索引，聚合等。最终会趋向于语句执行越来越慢 等问题。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221154397.png" alt="image-20220622115444326" style="zoom:67%;"><p>关注下临时表设置是否合理(tmp_table_size，max_heap_table_size）,临时表缓存 大概16M~128M既可以，如果已经非常大，说明SQL要进行优化.</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">status</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Created%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.10.30/202209221707754.png" alt="image-20220922170741603" style="zoom:80%;"><h2 id="文件表数量" tabindex="-1">文件表数量 <a class="header-anchor" href="#文件表数量" aria-label="Permalink to &quot;文件表数量&quot;">​</a></h2><p>说明底层ibd，frm 文件太多 或 操作系统 /etc/security/limits.conf设置太小导致</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221155384.png" alt="image-20220622115517290" style="zoom:67%;"><p>需要协调的参数有5个需要按照实际情况进行调整：</p><blockquote><p>innodb_open_files open_files_limit table_open_cache table_open_cache_instances table_space_definition_cache</p></blockquote><h2 id="底层page相关操作" tabindex="-1">底层page相关操作 <a class="header-anchor" href="#底层page相关操作" aria-label="Permalink to &quot;底层page相关操作&quot;">​</a></h2><p>innodb引擎对于page的操作。</p><p>特别是Handler_read_rnd_next 对于性能影响非常大。主要体现SQL语句方面不使用索引，全表扫描情况。大数据量随机读之类的。 <img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221155861.png" alt="image-20220622115553787" style="zoom:67%;"></p><h2 id="binlog情况" tabindex="-1">binlog情况 <a class="header-anchor" href="#binlog情况" aria-label="Permalink to &quot;binlog情况&quot;">​</a></h2><p>binlog是逻辑写入，一旦变更量多之后（insert，delete，update，ddl），binlog缓存刷新频率过高，影响一定的性能，带来迟缓效应。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221156503.png" alt="image-20220622115617432" style="zoom:67%;"><p>binlog_cache_size默认是32k，建议范围在1M~16M以内 ，如果超过这个值 就会使用临时表，所以MySQL不适合一些大事务。</p><h2 id="线程" tabindex="-1">线程 <a class="header-anchor" href="#线程" aria-label="Permalink to &quot;线程&quot;">​</a></h2><p>线程信息往往代表mysql链接情况。比如频繁的短连接可能对于mysql穷住，内存无法释放等问题。 当前执行的线程数也不能太多，会达到处理的瓶颈。 <img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221156960.png" alt="image-20220622115646890" style="zoom:67%;"></p><h2 id="链接错误" tabindex="-1">链接错误 <a class="header-anchor" href="#链接错误" aria-label="Permalink to &quot;链接错误&quot;">​</a></h2><p>当通信故障错误出现时，MySQL的状态变量Aborted_clients和Aborted_connects的计数会增加。这两个状态变量描述了链接中断，登录MySQL失败的计数。</p><p>客户端无权限,密码有误,连接包错误,连接时间限制，客户端没有进行关闭,突然终止 等。 参数timeout不合理也会出现这些值上升。（connect_timeout，wait_timeout，interactive_timeout net_read_timeout，net_write_timeout） <img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221157247.png" alt="image-20220622115713183" style="zoom:67%;"></p><h2 id="ddl语言情况" tabindex="-1">DDL语言情况 <a class="header-anchor" href="#ddl语言情况" aria-label="Permalink to &quot;DDL语言情况&quot;">​</a></h2><p>经验告诉，在MySQL使用触发器，存储过程，函数等存在很多隐患。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221157858.png" alt="image-20220622115737783" style="zoom:67%;"><h2 id="连接数-connects" tabindex="-1">连接数（Connects） <a class="header-anchor" href="#连接数-connects" aria-label="Permalink to &quot;连接数（Connects）&quot;">​</a></h2><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 最大使用连接数</span></span>
<span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">status</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Max_used_connections</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#A6ACCD;"># 当前打开的连接数</span></span>
<span class="line"><span style="color:#A6ACCD;">show </span><span style="color:#F78C6C;">status</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">like</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Threads_connected</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><h2 id="缓存" tabindex="-1">缓存 <a class="header-anchor" href="#缓存" aria-label="Permalink to &quot;缓存&quot;">​</a></h2><ul><li>未从缓冲池读取的次数：show status like ‘Innodb_buffer_pool_reads’</li><li>从缓冲池读取的次数：show status like ‘Innodb_buffer_pool_read_requests’</li><li>缓冲池的总页数：show status like ‘Innodb_buffer_pool_pages_total’</li><li>缓冲池空闲的页数：show status like ‘Innodb_buffer_pool_pages_free’</li><li>缓存命中率计算：（1-Innodb_buffer_pool_reads/Innodb_buffer_pool_read_requests）*100%</li><li>缓存池使用率为：((Innodb_buffer_pool_pages_total-Innodb_buffer_pool_pages_free）/Innodb_buffer_pool_pages_total）*100%</li></ul><h2 id="吞吐-database-throughputs" tabindex="-1">吞吐（Database throughputs） <a class="header-anchor" href="#吞吐-database-throughputs" aria-label="Permalink to &quot;吞吐（Database throughputs）&quot;">​</a></h2><ul><li>发送吞吐量：show status like &#39;Bytes_sent&#39;</li><li>接收吞吐量：show status like &#39;Bytes_received&#39;</li><li>总吞吐量：Bytes_sent+Bytes_received</li></ul><h2 id="其他" tabindex="-1">其他 <a class="header-anchor" href="#其他" aria-label="Permalink to &quot;其他&quot;">​</a></h2><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.11/202206221158957.png" alt="image-20220622115800875" style="zoom:67%;"></div></div></main><footer class="VPDocFooter" data-v-6b87e69f data-v-37656e44><!--[--><!--]--><!----><nav class="prev-next" data-v-37656e44><div class="pager" data-v-37656e44><a class="pager-link prev" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E8%AE%BE%E8%AE%A1.html" data-v-37656e44><span class="desc" data-v-37656e44>Previous page</span><span class="title" data-v-37656e44>MySQL设计</span></a></div><div class="pager" data-v-37656e44><a class="pager-link next" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8.html" data-v-37656e44><span class="desc" data-v-37656e44>Next page</span><span class="title" data-v-37656e44>分库分表</span></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"2、数据库_mysql_mysql面试_基础.md\":\"40da680a\",\"1、学前端_5、小程序_小程序项目.md\":\"60a1629b\",\"1、学前端_4、node_知识篇.md\":\"a7fb500e\",\"1、学前端_2、js_ts_es6 进阶.md\":\"6d07ba10\",\"1、学前端_3、vue_vue3_vue3进阶.md\":\"7ac622b4\",\"5、运维_jenkins.md\":\"929081f8\",\"1、学前端_2、js_ts_typescript.md\":\"875a4aa4\",\"2、数据库_mysql_mysql核心_设计.md\":\"7faf46d1\",\"2、数据库_mysql_mysql核心_基础.md\":\"d8e97f3e\",\"1、学前端_1、html_css_html基础.md\":\"7584d076\",\"1、学前端_5、专题篇_问题篇.md\":\"e893aaa2\",\"2、数据库_mysql_mysql面试_进阶.md\":\"f934806d\",\"3、springboot_运维_原理.md\":\"f4a39db6\",\"2、数据库_influxdb.md\":\"6e1711e1\",\"3、springboot_新特性.md\":\"cdf3e307\",\"mybatis_mybatisplus_jpa.md\":\"8e41681b\",\"1、学前端_5、小程序_小程序优化.md\":\"a2185198\",\"2、数据库_redis_redis基础.md\":\"856df0e0\",\"linux_实用脚本.md\":\"f2299dd5\",\"4、微服务_必备_分布式基础.md\":\"d49863d5\",\"2、数据库_redis_redis优化.md\":\"e66ae32f\",\"4、微服务_springsecurity_进阶篇.md\":\"235a8e9e\",\"5、运维_chatgpt.md\":\"10db3823\",\"2、数据库_mysql_分库分表.md\":\"e1c8a095\",\"start.md\":\"9bc1ff8d\",\"5、运维_github.md\":\"2ec6c735\",\"java学前端_css.md\":\"f11b47f0\",\"1、学前端_5、专题篇_知识篇.md\":\"a463ed8d\",\"linux_软件部署.md\":\"d6722925\",\"2、数据库_neo4j.md\":\"97ad22ac\",\"team.md\":\"ce467a6a\",\"nginx_实战篇.md\":\"7785486e\",\"index.md\":\"8c3ec167\",\"计算机基础_计算机网络_网络基础.md\":\"7a54a85d\",\"1、学前端_4、node_进阶篇.md\":\"60f6db69\",\"java_java集合.md\":\"a049b313\",\"1、学前端_3、vue_vue3_vue3高级.md\":\"614d1516\",\"1、学前端_5、小程序_微信小程序.md\":\"9a4be771\",\"5、运维_netty.md\":\"12ca0278\",\"2、数据库_mysql_mysql核心_运维.md\":\"83f97c16\",\"idea_vs code.md\":\"afdcb593\",\"java学前端_vue3_组件.md\":\"1086884e\",\"idea_chrome.md\":\"4a32afbc\",\"云原生_k8s.md\":\"db58e65a\",\"2、数据库_mysql_mysql核心_进阶.md\":\"61d16dff\",\"ssm_springbatch.md\":\"f799ab4a\",\"三高_分布式.md\":\"db1b8a1b\",\"2、数据库_elasticsearch_1、es基础.md\":\"04d17448\",\"linux_linux基础.md\":\"4b0bf394\",\"idea_idea插件.md\":\"fa86e45a\",\"可视化 _ 监控_可视化大屏.md\":\"004553bd\",\"2、数据库_mongodb_整合.md\":\"3c47d7f4\",\"4、微服务_springsecurity_基础篇.md\":\"534a3401\",\"4、微服务_进阶.md\":\"69095c58\",\"计算机基础_计算机基础_操作系统.md\":\"0f75d113\",\"可视化 _ 监控_zabbix.md\":\"71f2270e\",\"nginx_基础篇.md\":\"c7d8bb50\",\"1、学前端_4、node_项目实战.md\":\"bc5065b8\",\"2、数据库_redis_redis原理.md\":\"5cedf685\",\"可视化 _ 监控_监控基础.md\":\"ac56ce4d\",\"三高_高并发.md\":\"ea9ffc99\",\"2、数据库_redis_redis高级.md\":\"1d5872f6\",\"1、学前端_4、node_基础篇.md\":\"581cc13a\",\"2、数据库_mongodb_基础.md\":\"fb7a0a29\",\"idea_idea基础.md\":\"6f2f9638\",\"4、微服务_必备_sentinel.md\":\"2edfbf6c\",\"2、数据库_elasticsearch_3、es高级.md\":\"ef146606\",\"1、学前端_3、vue_vue3_vue3新语法.md\":\"8afd5409\",\"消息中间件_canal.md\":\"3949163c\",\"ssm_maven.md\":\"2c5e12ed\",\"4、微服务_springsecurity_高级篇.md\":\"882d3ff3\",\"linux_linux进阶.md\":\"188ef7b4\",\"计算机基础_设计模式_uml.md\":\"634ba256\",\"计算机基础_算法_leetcode.md\":\"77162fb9\",\"项目实战_小兔鲜_进阶篇1.md\":\"17c52c81\",\"1、学前端_2、js_ts_es6 基础.md\":\"fda3f18b\",\"项目实战_小兔鲜_进阶篇2.md\":\"a0f23006\",\"软件测试_测试基础.md\":\"8c1060cd\",\"2、数据库_redis_本地缓存.md\":\"00617fe6\",\"nginx_面试篇.md\":\"e3fb373a\",\"mybatis_mybatisplus_mybatis.md\":\"9239e0ad\",\"linux_shell.md\":\"ae53d83b\",\"2、数据库_mysql_mysql核心_优化.md\":\"36230425\",\"项目实战_项目推荐.md\":\"f9d97630\",\"mybatis_mybatisplus_mybatisplus.md\":\"0030fd35\",\"项目实战_百度地图_进阶篇.md\":\"c8b93267\",\"三高_高可用.md\":\"323840c5\",\"java_java新特性.md\":\"22abf56d\",\"软件测试_压力测试.md\":\"9ab44440\",\"java学前端_html_js.md\":\"e0fcd240\",\"2、数据库_redis_redis实战.md\":\"d6daeeab\",\"nginx_进阶篇.md\":\"e6b63195\",\"三高_秒杀.md\":\"3878bb64\",\"5、运维_git.md\":\"0264925c\",\"java_java进阶.md\":\"e79cb5b4\",\"并发 _ 多线程_基础篇.md\":\"7adbfac5\",\"项目实战_百度地图_基础篇.md\":\"8afa5954\",\"java学前端_react.md\":\"3ec827dd\",\"1、学前端_1、html_css_css基础.md\":\"01b56712\",\"项目实战_小兔鲜_基础篇.md\":\"646f5df5\",\"1、学前端_2、js_ts_js 基础.md\":\"cb13e36f\",\"可视化 _ 监控_监控进阶.md\":\"0cdbc292\",\"计算机基础_设计模式_基础篇.md\":\"51617287\",\"计算机基础_数据结构_基础篇.md\":\"b2bfd8d4\",\"项目实战_苍穹外卖_进阶篇.md\":\"48415e41\",\"ssm_spring.md\":\"ab514659\",\"消息中间件_rabbitmq.md\":\"45b1eb28\",\"1、学前端_1、html_css_网页进阶.md\":\"db998248\",\"消息中间件_kafka.md\":\"b747dabf\",\"云原生_docker.md\":\"983c7ba7\",\"4、微服务_必备_分布式锁.md\":\"5af1cf8d\",\"消息中间件_rocketmq.md\":\"d441da85\",\"项目实战_黑马头条_基础篇.md\":\"b05af3a6\",\"ssm_springmvc.md\":\"81b9714f\",\"项目实战_支付.md\":\"1d7407dd\",\"项目实战_黑马头条_进阶篇2.md\":\"bff0015b\",\"项目实战_黑马头条_进阶篇.md\":\"19f18388\",\"java学前端_vue2_组件.md\":\"58c6b1df\",\"3、springboot_基础篇.md\":\"529c66f4\",\"3、springboot_应用篇.md\":\"8b92aa61\",\"项目实战_黑马头条_高级篇.md\":\"227c08c1\",\"1、学前端_5、小程序_uniapp.md\":\"71a282b4\",\"项目实战_云尚办公_基础篇.md\":\"1fe188ba\",\"并发 _ 多线程_并发完善.md\":\"26619c46\",\"1、学前端_2、js_ts_js 进阶.md\":\"657dfb8f\",\"java_java高级.md\":\"23782d1a\",\"java_java基础.md\":\"86d67c77\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"VitePress\",\"description\":\"A VitePress site\",\"base\":\"/notebook/\",\"head\":[],\"appearance\":true,\"themeConfig\":{\"algolia\":{\"appId\":\"DW7O63I9IR\",\"apiKey\":\"f8ed758cdb288a8b06542bc35923c1a1\",\"indexName\":\"notebook\"},\"sidebar\":[{\"text\":\"Java\",\"collapsed\":true,\"items\":[{\"text\":\"Java基础\",\"link\":\"/Java/Java基础\"},{\"text\":\"Java新特性\",\"link\":\"/Java/Java新特性\"},{\"text\":\"Java进阶\",\"link\":\"/Java/Java进阶\"},{\"text\":\"Java集合\",\"link\":\"/Java/Java集合\"},{\"text\":\"Java高级\",\"link\":\"/Java/Java高级\"}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux基础\",\"link\":\"/Linux/Linux基础\"},{\"text\":\"Linux新特性\",\"link\":\"/Linux/Linux进阶\"},{\"text\":\"Shell脚本\",\"link\":\"/Linux/Shell\"},{\"text\":\"实用脚本\",\"link\":\"/Linux/实用脚本\"},{\"text\":\"软件部署\",\"link\":\"/Linux/软件部署\"}]},{\"text\":\"Nginx\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/Nginx/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/Nginx/进阶篇\"},{\"text\":\"实战篇\",\"link\":\"/Nginx/实战篇\"},{\"text\":\"面试篇\",\"link\":\"/Nginx/面试篇\"}]},{\"text\":\"SSM\",\"collapsed\":true,\"items\":[{\"text\":\"Maven\",\"link\":\"/SSM/Maven\"},{\"text\":\"Spring\",\"link\":\"/SSM/Spring\"},{\"text\":\"SpringMVC\",\"link\":\"/SSM/SpringMVC\"},{\"text\":\"SpringBatch\",\"link\":\"/SSM/SpringBatch\"}]},{\"text\":\"SpringBoot\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/3、SpringBoot/基础篇\"},{\"text\":\"应用篇\",\"link\":\"/3、SpringBoot/应用篇\"},{\"text\":\"新特性\",\"link\":\"/3、SpringBoot/新特性\"},{\"text\":\"运维&原理\",\"link\":\"/3、SpringBoot/运维&原理\"}]},{\"text\":\"SpringCloud\",\"collapsed\":true,\"items\":[{\"text\":\"SpringCloud\",\"link\":\"/4、微服务/进阶\"},{\"text\":\"Sentinel\",\"link\":\"/4、微服务/必备/Sentinel\"}]},{\"text\":\"SpringSecurity\",\"collapsed\":true,\"items\":[{\"text\":\"SpringSecurity基础篇\",\"link\":\"/4、微服务/SpringSecurity/基础篇\"},{\"text\":\"SpringSecurity进阶篇\",\"link\":\"/4、微服务/SpringSecurity/进阶篇\"},{\"text\":\"SpringSecurity高级篇\",\"link\":\"/4、微服务/SpringSecurity/高级篇\"}]},{\"text\":\"Mybatis & MybatisPlus\",\"collapsed\":true,\"items\":[{\"text\":\"Mybatis\",\"link\":\"/Mybatis&MybatisPlus/Mybatis\"},{\"text\":\"MybatisPlus\",\"link\":\"/Mybatis&MybatisPlus/MybatisPlus\"},{\"text\":\"JPA\",\"link\":\"/Mybatis&MybatisPlus/JPA\"}]},{\"text\":\"Git & ChatGPT\",\"collapsed\":true,\"items\":[{\"text\":\"Git\",\"link\":\"/5、运维/Git\"},{\"text\":\"Github\",\"link\":\"/5、运维/Github\"},{\"text\":\"ChatGPT\",\"link\":\"/5、运维/ChatGPT\"},{\"text\":\"Jenkins\",\"link\":\"/5、运维/Jenkins\"},{\"text\":\"Netty\",\"link\":\"/5、运维/Netty\"}]},{\"text\":\"数据库\",\"collapsed\":true,\"items\":[{\"text\":\"MySQL\",\"collapsed\":true,\"items\":[{\"text\":\"MySQL基础\",\"link\":\"/2、数据库/MySQL/MySQL核心/基础\"},{\"text\":\"MySQL进阶\",\"link\":\"/2、数据库/MySQL/MySQL核心/进阶\"},{\"text\":\"MySQL优化\",\"link\":\"/2、数据库/MySQL/MySQL核心/优化\"},{\"text\":\"MySQL设计\",\"link\":\"/2、数据库/MySQL/MySQL核心/设计\"},{\"text\":\"MySQL运维\",\"link\":\"/2、数据库/MySQL/MySQL核心/运维\"},{\"text\":\"分库分表\",\"link\":\"/2、数据库/MySQL/分库分表\"}]},{\"text\":\"Redis\",\"collapsed\":true,\"items\":[{\"text\":\"Redis基础\",\"link\":\"/2、数据库/Redis/Redis基础\"},{\"text\":\"Redis优化\",\"link\":\"/2、数据库/Redis/Redis优化\"},{\"text\":\"Redis原理\",\"link\":\"/2、数据库/Redis/Redis原理\"},{\"text\":\"Redis高级\",\"link\":\"/2、数据库/Redis/Redis高级\"},{\"text\":\"Redis实战\",\"link\":\"/2、数据库/Redis/Redis实战\"},{\"text\":\"本地缓存\",\"link\":\"/2、数据库/Redis/本地缓存\"}]},{\"text\":\"MongoDB\",\"collapsed\":true,\"items\":[{\"text\":\"MongoDB基础\",\"link\":\"/2、数据库/MongoDB/基础\"},{\"text\":\"MongoDB进阶\",\"link\":\"/2、数据库/MongoDB/整合\"}]},{\"text\":\"ElasticSearch\",\"collapsed\":true,\"items\":[{\"text\":\"ES基础\",\"link\":\"/2、数据库/ElasticSearch/1、ES基础\"},{\"text\":\"ES高级\",\"link\":\"/2、数据库/ElasticSearch/3、ES高级\"}]},{\"text\":\"InfluxDB\",\"link\":\"/2、数据库/influxdb\"},{\"text\":\"Neo4j\",\"link\":\"/2、数据库/Neo4j\"}]},{\"text\":\"高并发 & 秒杀 & 分布式\",\"collapsed\":true,\"items\":[{\"text\":\"分布式理论\",\"link\":\"/三高/分布式\"},{\"text\":\"分布式锁\",\"link\":\"/4、微服务/必备/分布式锁\"},{\"text\":\"秒杀\",\"link\":\"/三高/秒杀\"},{\"text\":\"高可用\",\"link\":\"/三高/高可用\"},{\"text\":\"高并发\",\"link\":\"/三高/高并发\"}]},{\"text\":\"云原生\",\"collapsed\":true,\"items\":[{\"text\":\"Docker\",\"link\":\"/云原生/Docker\"},{\"text\":\"K8S\",\"link\":\"/云原生/K8S\"}]},{\"text\":\"可视化 & 监控\",\"collapsed\":true,\"items\":[{\"text\":\"监控基础\",\"link\":\"/可视化 & 监控/监控基础\"},{\"text\":\"监控进阶\",\"link\":\"/可视化 & 监控/监控进阶\"},{\"text\":\"可视化大屏\",\"link\":\"/可视化 & 监控/可视化大屏\"},{\"text\":\"Zabbix\",\"link\":\"/可视化 & 监控/Zabbix\"}]},{\"text\":\"学前端\",\"collapsed\":true,\"items\":[{\"text\":\"HTML+CSS\",\"collapsed\":true,\"items\":[{\"text\":\"HTML基础\",\"link\":\"/1、学前端/1、HTML+CSS/HTML基础\"},{\"text\":\"CSS基础\",\"link\":\"/1、学前端/1、HTML+CSS/CSS基础\"},{\"text\":\"网页进阶\",\"link\":\"/1、学前端/1、HTML+CSS/网页进阶\"}]},{\"text\":\"JS+TS\",\"collapsed\":true,\"items\":[{\"text\":\"JS基础\",\"link\":\"/1、学前端/2、JS+TS/JS 基础\"},{\"text\":\"JS进阶\",\"link\":\"/1、学前端/2、JS+TS/JS 进阶\"},{\"text\":\"ES6基础\",\"link\":\"/1、学前端/2、JS+TS/ES6 基础\"},{\"text\":\"ES6进阶\",\"link\":\"/1、学前端/2、JS+TS/ES6 进阶\"},{\"text\":\"TS基础\",\"link\":\"/1、学前端/2、JS+TS/TypeScript\"}]},{\"text\":\"NodeJS\",\"collapsed\":true,\"items\":[{\"text\":\"Node基础\",\"link\":\"/1、学前端/4、Node/基础篇\"},{\"text\":\"Node进阶\",\"link\":\"/1、学前端/4、Node/进阶篇\"},{\"text\":\"项目实战\",\"link\":\"/1、学前端/4、Node/项目实战\"}]},{\"text\":\"Vue\",\"collapsed\":true,\"items\":[{\"text\":\"Vue3进阶\",\"link\":\"/1、学前端/3、Vue/Vue3/Vue3进阶\"},{\"text\":\"Vue3高级\",\"link\":\"/1、学前端/3、Vue/Vue3/Vue3高级\"},{\"text\":\"Vue3新语法\",\"link\":\"/1、学前端/3、Vue/Vue3/Vue3新语法\"},{\"text\":\"项目实战\",\"link\":\"/1、学前端/3、Vue/Vue2/Vue2项目\"}]},{\"text\":\"小程序\",\"collapsed\":true,\"items\":[{\"text\":\"小程序基础\",\"link\":\"/1、学前端/5、小程序/微信小程序\"},{\"text\":\"小程序优化\",\"link\":\"/1、学前端/5、小程序/小程序优化\"},{\"text\":\"uniapp\",\"link\":\"/1、学前端/5、小程序/uniapp\"},{\"text\":\"项目实战\",\"link\":\"/1、学前端/5、小程序/小程序项目\"}]}]},{\"text\":\"计算机基础\",\"collapsed\":true,\"items\":[{\"text\":\"数据结构\",\"link\":\"/计算机基础/数据结构/基础篇\"},{\"text\":\"操作系统\",\"link\":\"/计算机基础/计算机基础/操作系统\"},{\"text\":\"设计模式\",\"link\":\"/计算机基础/设计模式/基础篇\"},{\"text\":\"计算机网络\",\"link\":\"/计算机基础/计算机网络/网络基础\"},{\"text\":\"UML\",\"link\":\"/计算机基础/设计模式/UML\"},{\"text\":\"LeetCode\",\"link\":\"/计算机基础/算法/LeetCode\"}]},{\"text\":\"项目实战\",\"collapsed\":true,\"items\":[{\"text\":\"云尚办公\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/云尚办公/基础篇\"}]},{\"text\":\"小兔鲜\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/小兔鲜/基础篇\"},{\"text\":\"进阶篇1\",\"link\":\"/项目实战/小兔鲜/进阶篇1\"},{\"text\":\"进阶篇2\",\"link\":\"/项目实战/小兔鲜/进阶篇2\"}]},{\"text\":\"地图\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/百度地图/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/项目实战/百度地图/进阶篇\"}]},{\"text\":\"苍穹外卖\",\"collapsed\":true,\"items\":[{\"text\":\"进阶篇\",\"link\":\"/项目实战/苍穹外卖/进阶篇\"}]},{\"text\":\"黑马头条\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/黑马头条/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/项目实战/黑马头条/进阶篇\"},{\"text\":\"进阶篇2\",\"link\":\"/项目实战/黑马头条/进阶篇2\"},{\"text\":\"高级篇\",\"link\":\"/项目实战/黑马头条/高级篇\"}]},{\"text\":\"支付\",\"link\":\"/项目实战/支付\"},{\"text\":\"项目推荐\",\"link\":\"/项目实战/项目推荐\"}]},{\"text\":\"团队成员\",\"link\":\"/team\"}],\"siteTitle\":\"任硕的文档\",\"logo\":\"/Vue.png\",\"nav\":[{\"text\":\"Java学前端\",\"items\":[{\"items\":[{\"text\":\"HTML+JS\",\"link\":\"/Java学前端/HTML+JS\"},{\"text\":\"CSS\",\"link\":\"/Java学前端/CSS\"},{\"text\":\"Vue2+组件\",\"link\":\"/Java学前端/Vue2+组件\"},{\"text\":\"Vue3+组件\",\"link\":\"/Java学前端/Vue3+组件\"},{\"text\":\"React\",\"link\":\"/Java学前端/React\"}]}],\"activeMatch\":\"/Java/\"},{\"text\":\"软件测试\",\"items\":[{\"items\":[{\"text\":\"测试基础\",\"link\":\"/软件测试/测试基础\"},{\"text\":\"压力测试\",\"link\":\"/软件测试/压力测试\"}]}]},{\"text\":\"多线程\",\"items\":[{\"items\":[{\"text\":\"基础篇\",\"link\":\"/并发 & 多线程/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/并发 & 多线程/并发完善\"}]}]},{\"text\":\"开发工具\",\"items\":[{\"items\":[{\"text\":\"Chrome\",\"link\":\"/IDEA/Chrome\"},{\"text\":\"IDEA基础\",\"link\":\"/IDEA/IDEA基础\"},{\"text\":\"IDEA插件\",\"link\":\"/IDEA/IDEA插件\"},{\"text\":\"VS Code\",\"link\":\"/IDEA/VS Code\"}]}]},{\"text\":\"消息中间件\",\"items\":[{\"items\":[{\"text\":\"RabbitMQ\",\"link\":\"/消息中间件/RabbitMQ\"},{\"text\":\"RocketMQ\",\"link\":\"/消息中间件/RocketMQ\"},{\"text\":\"Kafka\",\"link\":\"/消息中间件/Kafka\"},{\"text\":\"Canal\",\"link\":\"/消息中间件/Canal\"}]}]}],\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/renshuo123/renshuo123.github.io\"},{\"icon\":\"twitter\",\"link\":\"#\"},{\"icon\":{\"svg\":\"<svg t=\\\"1676028692954\\\" class=\\\"icon\\\" ...</path></svg>\"},\"link\":\"https://github.com/\"}]},\"locales\":{},\"scrollOffset\":90,\"cleanUrls\":false}");</script>
    
  </body>
</html>